home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Python 1.3 / source code / Doc / tut.tex < prev    next >
LaTeX Document  |  1995-12-17  |  132.4 KB  |  [TEXT/R*ch]

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: LaTeX Document (document/latex).

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert LaTeX Document (document/latex) magic Supported
99% dexvert Texinfo Document (document/texInfo) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file LaTeX document text default
99% file TeX document text default
98% file LaTeX document, ASCII text, with CR line terminators default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/281 LaTeX (Subdocument) default
100% detectItEasy Format: plain text[CR] default (weak)


id metadata
keyvalue
macFileType[TEXT]
macFileCreator[R*ch]



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 5c 64 6f 63 75 6d 65 6e | 74 73 74 79 6c 65 5b 74 |\documen|tstyle[t|
|00000010| 77 6f 73 69 64 65 2c 31 | 31 70 74 2c 6d 79 66 6f |woside,1|1pt,myfo|
|00000020| 72 6d 61 74 5d 7b 72 65 | 70 6f 72 74 7d 0d 0d 5c |rmat]{re|port}..\|
|00000030| 74 69 74 6c 65 7b 50 79 | 74 68 6f 6e 20 54 75 74 |title{Py|thon Tut|
|00000040| 6f 72 69 61 6c 7d 0d 0d | 5c 69 6e 70 75 74 7b 62 |orial}..|\input{b|
|00000050| 6f 69 6c 65 72 70 6c 61 | 74 65 7d 0d 0d 5c 62 65 |oilerpla|te}..\be|
|00000060| 67 69 6e 7b 64 6f 63 75 | 6d 65 6e 74 7d 0d 0d 5c |gin{docu|ment}..\|
|00000070| 70 61 67 65 6e 75 6d 62 | 65 72 69 6e 67 7b 72 6f |pagenumb|ering{ro|
|00000080| 6d 61 6e 7d 0d 0d 5c 6d | 61 6b 65 74 69 74 6c 65 |man}..\m|aketitle|
|00000090| 0d 0d 5c 69 6e 70 75 74 | 7b 63 6f 70 79 72 69 67 |..\input|{copyrig|
|000000a0| 68 74 7d 0d 0d 5c 62 65 | 67 69 6e 7b 61 62 73 74 |ht}..\be|gin{abst|
|000000b0| 72 61 63 74 7d 0d 0d 5c | 6e 6f 69 6e 64 65 6e 74 |ract}..\|noindent|
|000000c0| 0d 50 79 74 68 6f 6e 20 | 69 73 20 61 20 73 69 6d |.Python |is a sim|
|000000d0| 70 6c 65 2c 20 79 65 74 | 20 70 6f 77 65 72 66 75 |ple, yet| powerfu|
|000000e0| 6c 20 70 72 6f 67 72 61 | 6d 6d 69 6e 67 20 6c 61 |l progra|mming la|
|000000f0| 6e 67 75 61 67 65 20 74 | 68 61 74 20 62 72 69 64 |nguage t|hat brid|
|00000100| 67 65 73 20 74 68 65 0d | 67 61 70 20 62 65 74 77 |ges the.|gap betw|
|00000110| 65 65 6e 20 43 20 61 6e | 64 20 73 68 65 6c 6c 20 |een C an|d shell |
|00000120| 70 72 6f 67 72 61 6d 6d | 69 6e 67 2c 20 61 6e 64 |programm|ing, and|
|00000130| 20 69 73 20 74 68 75 73 | 20 69 64 65 61 6c 6c 79 | is thus| ideally|
|00000140| 20 73 75 69 74 65 64 20 | 66 6f 72 0d 60 60 74 68 | suited |for.``th|
|00000150| 72 6f 77 2d 61 77 61 79 | 20 70 72 6f 67 72 61 6d |row-away| program|
|00000160| 6d 69 6e 67 27 27 0d 61 | 6e 64 20 72 61 70 69 64 |ming''.a|nd rapid|
|00000170| 20 70 72 6f 74 6f 74 79 | 70 69 6e 67 2e 20 20 49 | prototy|ping. I|
|00000180| 74 73 20 73 79 6e 74 61 | 78 20 69 73 20 70 75 74 |ts synta|x is put|
|00000190| 0d 74 6f 67 65 74 68 65 | 72 20 66 72 6f 6d 20 63 |.togethe|r from c|
|000001a0| 6f 6e 73 74 72 75 63 74 | 73 20 62 6f 72 72 6f 77 |onstruct|s borrow|
|000001b0| 65 64 20 66 72 6f 6d 20 | 61 20 76 61 72 69 65 74 |ed from |a variet|
|000001c0| 79 20 6f 66 20 6f 74 68 | 65 72 20 6c 61 6e 67 75 |y of oth|er langu|
|000001d0| 61 67 65 73 3b 0d 6d 6f | 73 74 20 70 72 6f 6d 69 |ages;.mo|st promi|
|000001e0| 6e 65 6e 74 20 61 72 65 | 20 69 6e 66 6c 75 65 6e |nent are| influen|
|000001f0| 63 65 73 20 66 72 6f 6d | 20 41 42 43 2c 20 43 2c |ces from| ABC, C,|
|00000200| 20 4d 6f 64 75 6c 61 2d | 33 20 61 6e 64 20 49 63 | Modula-|3 and Ic|
|00000210| 6f 6e 2e 0d 0d 54 68 65 | 20 50 79 74 68 6f 6e 20 |on...The| Python |
|00000220| 69 6e 74 65 72 70 72 65 | 74 65 72 20 69 73 20 65 |interpre|ter is e|
|00000230| 61 73 69 6c 79 20 65 78 | 74 65 6e 64 65 64 20 77 |asily ex|tended w|
|00000240| 69 74 68 20 6e 65 77 20 | 66 75 6e 63 74 69 6f 6e |ith new |function|
|00000250| 73 20 61 6e 64 20 64 61 | 74 61 0d 74 79 70 65 73 |s and da|ta.types|
|00000260| 20 69 6d 70 6c 65 6d 65 | 6e 74 65 64 20 69 6e 20 | impleme|nted in |
|00000270| 43 2e 20 20 50 79 74 68 | 6f 6e 20 69 73 20 61 6c |C. Pyth|on is al|
|00000280| 73 6f 20 73 75 69 74 61 | 62 6c 65 20 61 73 20 61 |so suita|ble as a|
|00000290| 6e 20 65 78 74 65 6e 73 | 69 6f 6e 0d 6c 61 6e 67 |n extens|ion.lang|
|000002a0| 75 61 67 65 20 66 6f 72 | 20 68 69 67 68 6c 79 20 |uage for| highly |
|000002b0| 63 75 73 74 6f 6d 69 7a | 61 62 6c 65 20 43 20 61 |customiz|able C a|
|000002c0| 70 70 6c 69 63 61 74 69 | 6f 6e 73 20 73 75 63 68 |pplicati|ons such|
|000002d0| 20 61 73 20 65 64 69 74 | 6f 72 73 20 6f 72 0d 77 | as edit|ors or.w|
|000002e0| 69 6e 64 6f 77 20 6d 61 | 6e 61 67 65 72 73 2e 0d |indow ma|nagers..|
|000002f0| 0d 50 79 74 68 6f 6e 20 | 69 73 20 61 76 61 69 6c |.Python |is avail|
|00000300| 61 62 6c 65 20 66 6f 72 | 20 76 61 72 69 6f 75 73 |able for| various|
|00000310| 20 6f 70 65 72 61 74 69 | 6e 67 20 73 79 73 74 65 | operati|ng syste|
|00000320| 6d 73 2c 20 61 6d 6f 6e | 67 73 74 20 77 68 69 63 |ms, amon|gst whic|
|00000330| 68 0d 73 65 76 65 72 61 | 6c 20 66 6c 61 76 6f 72 |h.severa|l flavor|
|00000340| 73 20 6f 66 20 7b 5c 55 | 4e 49 58 7d 2c 20 41 6d |s of {\U|NIX}, Am|
|00000350| 6f 65 62 61 2c 20 74 68 | 65 20 41 70 70 6c 65 20 |oeba, th|e Apple |
|00000360| 4d 61 63 69 6e 74 6f 73 | 68 20 4f 2e 53 2e 2c 0d |Macintos|h O.S.,.|
|00000370| 61 6e 64 20 4d 53 2d 44 | 4f 53 2e 0d 0d 54 68 69 |and MS-D|OS...Thi|
|00000380| 73 20 74 75 74 6f 72 69 | 61 6c 20 69 6e 74 72 6f |s tutori|al intro|
|00000390| 64 75 63 65 73 20 74 68 | 65 20 72 65 61 64 65 72 |duces th|e reader|
|000003a0| 20 69 6e 66 6f 72 6d 61 | 6c 6c 79 20 74 6f 20 74 | informa|lly to t|
|000003b0| 68 65 20 62 61 73 69 63 | 20 63 6f 6e 63 65 70 74 |he basic| concept|
|000003c0| 73 0d 61 6e 64 20 66 65 | 61 74 75 72 65 73 20 6f |s.and fe|atures o|
|000003d0| 66 20 74 68 65 20 50 79 | 74 68 6f 6e 20 6c 61 6e |f the Py|thon lan|
|000003e0| 67 75 61 67 65 20 61 6e | 64 20 73 79 73 74 65 6d |guage an|d system|
|000003f0| 2e 20 20 49 74 20 68 65 | 6c 70 73 20 74 6f 20 68 |. It he|lps to h|
|00000400| 61 76 65 20 61 0d 50 79 | 74 68 6f 6e 20 69 6e 74 |ave a.Py|thon int|
|00000410| 65 72 70 72 65 74 65 72 | 20 68 61 6e 64 79 20 66 |erpreter| handy f|
|00000420| 6f 72 20 68 61 6e 64 73 | 2d 6f 6e 20 65 78 70 65 |or hands|-on expe|
|00000430| 72 69 65 6e 63 65 2c 20 | 62 75 74 20 61 73 20 74 |rience, |but as t|
|00000440| 68 65 20 65 78 61 6d 70 | 6c 65 73 0d 61 72 65 20 |he examp|les.are |
|00000450| 73 65 6c 66 2d 63 6f 6e | 74 61 69 6e 65 64 2c 20 |self-con|tained, |
|00000460| 74 68 65 20 74 75 74 6f | 72 69 61 6c 20 63 61 6e |the tuto|rial can|
|00000470| 20 62 65 20 72 65 61 64 | 20 6f 66 66 2d 6c 69 6e | be read| off-lin|
|00000480| 65 20 61 73 20 77 65 6c | 6c 2e 0d 0d 46 6f 72 20 |e as wel|l...For |
|00000490| 61 20 64 65 73 63 72 69 | 70 74 69 6f 6e 20 6f 66 |a descri|ption of|
|000004a0| 20 73 74 61 6e 64 61 72 | 64 20 6f 62 6a 65 63 74 | standar|d object|
|000004b0| 73 20 61 6e 64 20 6d 6f | 64 75 6c 65 73 2c 20 73 |s and mo|dules, s|
|000004c0| 65 65 20 74 68 65 20 7b | 5c 65 6d 20 50 79 74 68 |ee the {|\em Pyth|
|000004d0| 6f 6e 0d 4c 69 62 72 61 | 72 79 20 52 65 66 65 72 |on.Libra|ry Refer|
|000004e0| 65 6e 63 65 7d 20 64 6f | 63 75 6d 65 6e 74 2e 20 |ence} do|cument. |
|000004f0| 20 54 68 65 20 7b 5c 65 | 6d 20 50 79 74 68 6f 6e | The {\e|m Python|
|00000500| 20 52 65 66 65 72 65 6e | 63 65 20 4d 61 6e 75 61 | Referen|ce Manua|
|00000510| 6c 7d 20 67 69 76 65 73 | 0d 61 20 6d 6f 72 65 20 |l} gives|.a more |
|00000520| 66 6f 72 6d 61 6c 20 64 | 65 66 69 6e 69 74 69 6f |formal d|efinitio|
|00000530| 6e 20 6f 66 20 74 68 65 | 20 6c 61 6e 67 75 61 67 |n of the| languag|
|00000540| 65 2e 0d 0d 5c 65 6e 64 | 7b 61 62 73 74 72 61 63 |e...\end|{abstrac|
|00000550| 74 7d 0d 0d 5c 70 61 67 | 65 62 72 65 61 6b 0d 7b |t}..\pag|ebreak.{|
|00000560| 0d 5c 70 61 72 73 6b 69 | 70 20 3d 20 30 6d 6d 0d |.\parski|p = 0mm.|
|00000570| 5c 74 61 62 6c 65 6f 66 | 63 6f 6e 74 65 6e 74 73 |\tableof|contents|
|00000580| 0d 7d 0d 0d 5c 70 61 67 | 65 62 72 65 61 6b 0d 0d |.}..\pag|ebreak..|
|00000590| 5c 70 61 67 65 6e 75 6d | 62 65 72 69 6e 67 7b 61 |\pagenum|bering{a|
|000005a0| 72 61 62 69 63 7d 0d 0d | 0d 5c 63 68 61 70 74 65 |rabic}..|.\chapte|
|000005b0| 72 7b 57 68 65 74 74 69 | 6e 67 20 59 6f 75 72 20 |r{Whetti|ng Your |
|000005c0| 41 70 70 65 74 69 74 65 | 7d 0d 0d 49 66 20 79 6f |Appetite|}..If yo|
|000005d0| 75 20 65 76 65 72 20 77 | 72 6f 74 65 20 61 20 6c |u ever w|rote a l|
|000005e0| 61 72 67 65 20 73 68 65 | 6c 6c 20 73 63 72 69 70 |arge she|ll scrip|
|000005f0| 74 2c 20 79 6f 75 20 70 | 72 6f 62 61 62 6c 79 20 |t, you p|robably |
|00000600| 6b 6e 6f 77 20 74 68 69 | 73 0d 66 65 65 6c 69 6e |know thi|s.feelin|
|00000610| 67 3a 20 79 6f 75 27 64 | 20 6c 6f 76 65 20 74 6f |g: you'd| love to|
|00000620| 20 61 64 64 20 79 65 74 | 20 61 6e 6f 74 68 65 72 | add yet| another|
|00000630| 20 66 65 61 74 75 72 65 | 2c 20 62 75 74 20 69 74 | feature|, but it|
|00000640| 27 73 20 61 6c 72 65 61 | 64 79 20 73 6f 0d 73 6c |'s alrea|dy so.sl|
|00000650| 6f 77 2c 20 61 6e 64 20 | 73 6f 20 62 69 67 2c 20 |ow, and |so big, |
|00000660| 61 6e 64 20 73 6f 20 63 | 6f 6d 70 6c 69 63 61 74 |and so c|omplicat|
|00000670| 65 64 3b 20 6f 72 20 74 | 68 65 20 66 65 61 74 75 |ed; or t|he featu|
|00000680| 72 65 20 69 6e 76 6f 6c | 76 65 73 20 61 20 73 79 |re invol|ves a sy|
|00000690| 73 74 65 6d 0d 63 61 6c | 6c 20 6f 72 20 6f 74 68 |stem.cal|l or oth|
|000006a0| 65 72 20 66 75 6e 63 74 | 69 6f 6e 20 74 68 61 74 |er funct|ion that|
|000006b0| 20 69 73 20 6f 6e 6c 79 | 20 61 63 63 65 73 73 69 | is only| accessi|
|000006c0| 62 6c 65 20 66 72 6f 6d | 20 43 20 5c 6c 64 6f 74 |ble from| C \ldot|
|000006d0| 73 20 20 55 73 75 61 6c | 6c 79 0d 74 68 65 20 70 |s Usual|ly.the p|
|000006e0| 72 6f 62 6c 65 6d 20 61 | 74 20 68 61 6e 64 20 69 |roblem a|t hand i|
|000006f0| 73 6e 27 74 20 73 65 72 | 69 6f 75 73 20 65 6e 6f |sn't ser|ious eno|
|00000700| 75 67 68 20 74 6f 20 77 | 61 72 72 61 6e 74 20 72 |ugh to w|arrant r|
|00000710| 65 77 72 69 74 69 6e 67 | 20 74 68 65 0d 73 63 72 |ewriting| the.scr|
|00000720| 69 70 74 20 69 6e 20 43 | 3b 20 70 65 72 68 61 70 |ipt in C|; perhap|
|00000730| 73 20 62 65 63 61 75 73 | 65 20 74 68 65 20 70 72 |s becaus|e the pr|
|00000740| 6f 62 6c 65 6d 20 72 65 | 71 75 69 72 65 73 20 76 |oblem re|quires v|
|00000750| 61 72 69 61 62 6c 65 2d | 6c 65 6e 67 74 68 0d 73 |ariable-|length.s|
|00000760| 74 72 69 6e 67 73 20 6f | 72 20 6f 74 68 65 72 20 |trings o|r other |
|00000770| 64 61 74 61 20 74 79 70 | 65 73 20 28 6c 69 6b 65 |data typ|es (like|
|00000780| 20 73 6f 72 74 65 64 20 | 6c 69 73 74 73 20 6f 66 | sorted |lists of|
|00000790| 20 66 69 6c 65 20 6e 61 | 6d 65 73 29 20 74 68 61 | file na|mes) tha|
|000007a0| 74 20 61 72 65 0d 65 61 | 73 79 20 69 6e 20 74 68 |t are.ea|sy in th|
|000007b0| 65 20 73 68 65 6c 6c 20 | 62 75 74 20 6c 6f 74 73 |e shell |but lots|
|000007c0| 20 6f 66 20 77 6f 72 6b | 20 74 6f 20 69 6d 70 6c | of work| to impl|
|000007d0| 65 6d 65 6e 74 20 69 6e | 20 43 3b 20 6f 72 20 70 |ement in| C; or p|
|000007e0| 65 72 68 61 70 73 20 6a | 75 73 74 0d 62 65 63 61 |erhaps j|ust.beca|
|000007f0| 75 73 65 20 79 6f 75 27 | 72 65 20 6e 6f 74 20 73 |use you'|re not s|
|00000800| 75 66 66 69 63 69 65 6e | 74 6c 79 20 66 61 6d 69 |ufficien|tly fami|
|00000810| 6c 69 61 72 20 77 69 74 | 68 20 43 2e 0d 0d 49 6e |liar wit|h C...In|
|00000820| 20 73 75 63 68 20 63 61 | 73 65 73 2c 20 50 79 74 | such ca|ses, Pyt|
|00000830| 68 6f 6e 20 6d 61 79 20 | 62 65 20 6a 75 73 74 20 |hon may |be just |
|00000840| 74 68 65 20 6c 61 6e 67 | 75 61 67 65 20 66 6f 72 |the lang|uage for|
|00000850| 20 79 6f 75 2e 20 20 50 | 79 74 68 6f 6e 20 69 73 | you. P|ython is|
|00000860| 0d 73 69 6d 70 6c 65 20 | 74 6f 20 75 73 65 2c 20 |.simple |to use, |
|00000870| 62 75 74 20 69 74 20 69 | 73 20 61 20 72 65 61 6c |but it i|s a real|
|00000880| 20 70 72 6f 67 72 61 6d | 6d 69 6e 67 20 6c 61 6e | program|ming lan|
|00000890| 67 75 61 67 65 2c 20 6f | 66 66 65 72 69 6e 67 20 |guage, o|ffering |
|000008a0| 6d 75 63 68 0d 6d 6f 72 | 65 20 73 74 72 75 63 74 |much.mor|e struct|
|000008b0| 75 72 65 20 61 6e 64 20 | 73 75 70 70 6f 72 74 20 |ure and |support |
|000008c0| 66 6f 72 20 6c 61 72 67 | 65 20 70 72 6f 67 72 61 |for larg|e progra|
|000008d0| 6d 73 20 74 68 61 6e 20 | 74 68 65 20 73 68 65 6c |ms than |the shel|
|000008e0| 6c 20 68 61 73 2e 20 20 | 4f 6e 0d 74 68 65 20 6f |l has. |On.the o|
|000008f0| 74 68 65 72 20 68 61 6e | 64 2c 20 69 74 20 61 6c |ther han|d, it al|
|00000900| 73 6f 20 6f 66 66 65 72 | 73 20 6d 75 63 68 20 6d |so offer|s much m|
|00000910| 6f 72 65 20 65 72 72 6f | 72 20 63 68 65 63 6b 69 |ore erro|r checki|
|00000920| 6e 67 20 74 68 61 6e 20 | 43 2c 20 61 6e 64 2c 0d |ng than |C, and,.|
|00000930| 62 65 69 6e 67 20 61 20 | 7b 5c 65 6d 20 76 65 72 |being a |{\em ver|
|00000940| 79 2d 68 69 67 68 2d 6c | 65 76 65 6c 20 6c 61 6e |y-high-l|evel lan|
|00000950| 67 75 61 67 65 7d 2c 20 | 69 74 20 68 61 73 20 68 |guage}, |it has h|
|00000960| 69 67 68 2d 6c 65 76 65 | 6c 20 64 61 74 61 20 74 |igh-leve|l data t|
|00000970| 79 70 65 73 0d 62 75 69 | 6c 74 20 69 6e 2c 20 73 |ypes.bui|lt in, s|
|00000980| 75 63 68 20 61 73 20 66 | 6c 65 78 69 62 6c 65 20 |uch as f|lexible |
|00000990| 61 72 72 61 79 73 20 61 | 6e 64 20 64 69 63 74 69 |arrays a|nd dicti|
|000009a0| 6f 6e 61 72 69 65 73 20 | 74 68 61 74 20 77 6f 75 |onaries |that wou|
|000009b0| 6c 64 20 63 6f 73 74 20 | 79 6f 75 0d 64 61 79 73 |ld cost |you.days|
|000009c0| 20 74 6f 20 69 6d 70 6c | 65 6d 65 6e 74 20 65 66 | to impl|ement ef|
|000009d0| 66 69 63 69 65 6e 74 6c | 79 20 69 6e 20 43 2e 20 |ficientl|y in C. |
|000009e0| 20 42 65 63 61 75 73 65 | 20 6f 66 20 69 74 73 20 | Because| of its |
|000009f0| 6d 6f 72 65 20 67 65 6e | 65 72 61 6c 20 64 61 74 |more gen|eral dat|
|00000a00| 61 0d 74 79 70 65 73 20 | 50 79 74 68 6f 6e 20 69 |a.types |Python i|
|00000a10| 73 20 61 70 70 6c 69 63 | 61 62 6c 65 20 74 6f 20 |s applic|able to |
|00000a20| 61 20 6d 75 63 68 20 6c | 61 72 67 65 72 20 70 72 |a much l|arger pr|
|00000a30| 6f 62 6c 65 6d 20 64 6f | 6d 61 69 6e 20 74 68 61 |oblem do|main tha|
|00000a40| 6e 20 7b 5c 65 6d 0d 41 | 77 6b 7d 20 6f 72 20 65 |n {\em.A|wk} or e|
|00000a50| 76 65 6e 20 7b 5c 65 6d | 20 50 65 72 6c 7d 2c 20 |ven {\em| Perl}, |
|00000a60| 79 65 74 20 6d 61 6e 79 | 20 74 68 69 6e 67 73 20 |yet many| things |
|00000a70| 61 72 65 20 61 74 20 6c | 65 61 73 74 20 61 73 20 |are at l|east as |
|00000a80| 65 61 73 79 20 69 6e 0d | 50 79 74 68 6f 6e 20 61 |easy in.|Python a|
|00000a90| 73 20 69 6e 20 74 68 6f | 73 65 20 6c 61 6e 67 75 |s in tho|se langu|
|00000aa0| 61 67 65 73 2e 0d 0d 50 | 79 74 68 6f 6e 20 61 6c |ages...P|ython al|
|00000ab0| 6c 6f 77 73 20 79 6f 75 | 20 74 6f 20 73 70 6c 69 |lows you| to spli|
|00000ac0| 74 20 75 70 20 79 6f 75 | 72 20 70 72 6f 67 72 61 |t up you|r progra|
|00000ad0| 6d 20 69 6e 20 6d 6f 64 | 75 6c 65 73 20 74 68 61 |m in mod|ules tha|
|00000ae0| 74 20 63 61 6e 20 62 65 | 0d 72 65 75 73 65 64 20 |t can be|.reused |
|00000af0| 69 6e 20 6f 74 68 65 72 | 20 50 79 74 68 6f 6e 20 |in other| Python |
|00000b00| 70 72 6f 67 72 61 6d 73 | 2e 20 20 49 74 20 63 6f |programs|. It co|
|00000b10| 6d 65 73 20 77 69 74 68 | 20 61 20 6c 61 72 67 65 |mes with| a large|
|00000b20| 20 63 6f 6c 6c 65 63 74 | 69 6f 6e 20 6f 66 0d 73 | collect|ion of.s|
|00000b30| 74 61 6e 64 61 72 64 20 | 6d 6f 64 75 6c 65 73 20 |tandard |modules |
|00000b40| 74 68 61 74 20 79 6f 75 | 20 63 61 6e 20 75 73 65 |that you| can use|
|00000b50| 20 61 73 20 74 68 65 20 | 62 61 73 69 73 20 6f 66 | as the |basis of|
|00000b60| 20 79 6f 75 72 20 70 72 | 6f 67 72 61 6d 73 20 2d | your pr|ograms -|
|00000b70| 2d 2d 20 6f 72 0d 61 73 | 20 65 78 61 6d 70 6c 65 |-- or.as| example|
|00000b80| 73 20 74 6f 20 73 74 61 | 72 74 20 6c 65 61 72 6e |s to sta|rt learn|
|00000b90| 69 6e 67 20 74 6f 20 70 | 72 6f 67 72 61 6d 20 69 |ing to p|rogram i|
|00000ba0| 6e 20 50 79 74 68 6f 6e | 2e 20 20 54 68 65 72 65 |n Python|. There|
|00000bb0| 20 61 72 65 20 61 6c 73 | 6f 0d 62 75 69 6c 74 2d | are als|o.built-|
|00000bc0| 69 6e 20 6d 6f 64 75 6c | 65 73 20 74 68 61 74 20 |in modul|es that |
|00000bd0| 70 72 6f 76 69 64 65 20 | 74 68 69 6e 67 73 20 6c |provide |things l|
|00000be0| 69 6b 65 20 66 69 6c 65 | 20 49 2f 4f 2c 20 73 79 |ike file| I/O, sy|
|00000bf0| 73 74 65 6d 20 63 61 6c | 6c 73 2c 0d 73 6f 63 6b |stem cal|ls,.sock|
|00000c00| 65 74 73 2c 20 61 6e 64 | 20 65 76 65 6e 20 61 20 |ets, and| even a |
|00000c10| 67 65 6e 65 72 69 63 20 | 69 6e 74 65 72 66 61 63 |generic |interfac|
|00000c20| 65 20 74 6f 20 77 69 6e | 64 6f 77 20 73 79 73 74 |e to win|dow syst|
|00000c30| 65 6d 73 20 28 53 54 44 | 57 49 4e 29 2e 0d 0d 50 |ems (STD|WIN)...P|
|00000c40| 79 74 68 6f 6e 20 69 73 | 20 61 6e 20 69 6e 74 65 |ython is| an inte|
|00000c50| 72 70 72 65 74 65 64 20 | 6c 61 6e 67 75 61 67 65 |rpreted |language|
|00000c60| 2c 20 77 68 69 63 68 20 | 63 61 6e 20 73 61 76 65 |, which |can save|
|00000c70| 20 79 6f 75 20 63 6f 6e | 73 69 64 65 72 61 62 6c | you con|siderabl|
|00000c80| 65 20 74 69 6d 65 0d 64 | 75 72 69 6e 67 20 70 72 |e time.d|uring pr|
|00000c90| 6f 67 72 61 6d 20 64 65 | 76 65 6c 6f 70 6d 65 6e |ogram de|velopmen|
|00000ca0| 74 20 62 65 63 61 75 73 | 65 20 6e 6f 20 63 6f 6d |t becaus|e no com|
|00000cb0| 70 69 6c 61 74 69 6f 6e | 20 61 6e 64 20 6c 69 6e |pilation| and lin|
|00000cc0| 6b 69 6e 67 20 69 73 0d | 6e 65 63 65 73 73 61 72 |king is.|necessar|
|00000cd0| 79 2e 20 20 54 68 65 20 | 69 6e 74 65 72 70 72 65 |y. The |interpre|
|00000ce0| 74 65 72 20 63 61 6e 20 | 62 65 20 75 73 65 64 20 |ter can |be used |
|00000cf0| 69 6e 74 65 72 61 63 74 | 69 76 65 6c 79 2c 20 77 |interact|ively, w|
|00000d00| 68 69 63 68 20 6d 61 6b | 65 73 20 69 74 0d 65 61 |hich mak|es it.ea|
|00000d10| 73 79 20 74 6f 20 65 78 | 70 65 72 69 6d 65 6e 74 |sy to ex|periment|
|00000d20| 20 77 69 74 68 20 66 65 | 61 74 75 72 65 73 20 6f | with fe|atures o|
|00000d30| 66 20 74 68 65 20 6c 61 | 6e 67 75 61 67 65 2c 20 |f the la|nguage, |
|00000d40| 74 6f 20 77 72 69 74 65 | 20 74 68 72 6f 77 2d 61 |to write| throw-a|
|00000d50| 77 61 79 0d 70 72 6f 67 | 72 61 6d 73 2c 20 6f 72 |way.prog|rams, or|
|00000d60| 20 74 6f 20 74 65 73 74 | 20 66 75 6e 63 74 69 6f | to test| functio|
|00000d70| 6e 73 20 64 75 72 69 6e | 67 20 62 6f 74 74 6f 6d |ns durin|g bottom|
|00000d80| 2d 75 70 20 70 72 6f 67 | 72 61 6d 20 64 65 76 65 |-up prog|ram deve|
|00000d90| 6c 6f 70 6d 65 6e 74 2e | 0d 49 74 20 69 73 20 61 |lopment.|.It is a|
|00000da0| 6c 73 6f 20 61 20 68 61 | 6e 64 79 20 64 65 73 6b |lso a ha|ndy desk|
|00000db0| 20 63 61 6c 63 75 6c 61 | 74 6f 72 2e 0d 0d 50 79 | calcula|tor...Py|
|00000dc0| 74 68 6f 6e 20 61 6c 6c | 6f 77 73 20 77 72 69 74 |thon all|ows writ|
|00000dd0| 69 6e 67 20 76 65 72 79 | 20 63 6f 6d 70 61 63 74 |ing very| compact|
|00000de0| 20 61 6e 64 20 72 65 61 | 64 61 62 6c 65 20 70 72 | and rea|dable pr|
|00000df0| 6f 67 72 61 6d 73 2e 20 | 20 50 72 6f 67 72 61 6d |ograms. | Program|
|00000e00| 73 0d 77 72 69 74 74 65 | 6e 20 69 6e 20 50 79 74 |s.writte|n in Pyt|
|00000e10| 68 6f 6e 20 61 72 65 20 | 74 79 70 69 63 61 6c 6c |hon are |typicall|
|00000e20| 79 20 6d 75 63 68 20 73 | 68 6f 72 74 65 72 20 74 |y much s|horter t|
|00000e30| 68 61 6e 20 65 71 75 69 | 76 61 6c 65 6e 74 20 43 |han equi|valent C|
|00000e40| 0d 70 72 6f 67 72 61 6d | 73 2c 20 66 6f 72 20 73 |.program|s, for s|
|00000e50| 65 76 65 72 61 6c 20 72 | 65 61 73 6f 6e 73 3a 0d |everal r|easons:.|
|00000e60| 5c 62 65 67 69 6e 7b 69 | 74 65 6d 69 7a 65 7d 0d |\begin{i|temize}.|
|00000e70| 5c 69 74 65 6d 0d 74 68 | 65 20 68 69 67 68 2d 6c |\item.th|e high-l|
|00000e80| 65 76 65 6c 20 64 61 74 | 61 20 74 79 70 65 73 20 |evel dat|a types |
|00000e90| 61 6c 6c 6f 77 20 79 6f | 75 20 74 6f 20 65 78 70 |allow yo|u to exp|
|00000ea0| 72 65 73 73 20 63 6f 6d | 70 6c 65 78 20 6f 70 65 |ress com|plex ope|
|00000eb0| 72 61 74 69 6f 6e 73 20 | 69 6e 20 61 0d 73 69 6e |rations |in a.sin|
|00000ec0| 67 6c 65 20 73 74 61 74 | 65 6d 65 6e 74 3b 0d 5c |gle stat|ement;.\|
|00000ed0| 69 74 65 6d 0d 73 74 61 | 74 65 6d 65 6e 74 20 67 |item.sta|tement g|
|00000ee0| 72 6f 75 70 69 6e 67 20 | 69 73 20 64 6f 6e 65 20 |rouping |is done |
|00000ef0| 62 79 20 69 6e 64 65 6e | 74 61 74 69 6f 6e 20 69 |by inden|tation i|
|00000f00| 6e 73 74 65 61 64 20 6f | 66 20 62 65 67 69 6e 2f |nstead o|f begin/|
|00000f10| 65 6e 64 0d 62 72 61 63 | 6b 65 74 73 3b 0d 5c 69 |end.brac|kets;.\i|
|00000f20| 74 65 6d 0d 6e 6f 20 76 | 61 72 69 61 62 6c 65 20 |tem.no v|ariable |
|00000f30| 6f 72 20 61 72 67 75 6d | 65 6e 74 20 64 65 63 6c |or argum|ent decl|
|00000f40| 61 72 61 74 69 6f 6e 73 | 20 61 72 65 20 6e 65 63 |arations| are nec|
|00000f50| 65 73 73 61 72 79 2e 0d | 5c 65 6e 64 7b 69 74 65 |essary..|\end{ite|
|00000f60| 6d 69 7a 65 7d 0d 0d 50 | 79 74 68 6f 6e 20 69 73 |mize}..P|ython is|
|00000f70| 20 7b 5c 65 6d 20 65 78 | 74 65 6e 73 69 62 6c 65 | {\em ex|tensible|
|00000f80| 7d 3a 20 69 66 20 79 6f | 75 20 6b 6e 6f 77 20 68 |}: if yo|u know h|
|00000f90| 6f 77 20 74 6f 20 70 72 | 6f 67 72 61 6d 20 69 6e |ow to pr|ogram in|
|00000fa0| 20 43 20 69 74 20 69 73 | 20 65 61 73 79 0d 74 6f | C it is| easy.to|
|00000fb0| 20 61 64 64 20 61 20 6e | 65 77 20 62 75 69 6c 74 | add a n|ew built|
|00000fc0| 2d 69 6e 0d 66 75 6e 63 | 74 69 6f 6e 20 6f 72 0d |-in.func|tion or.|
|00000fd0| 6d 6f 64 75 6c 65 20 74 | 6f 20 74 68 65 20 69 6e |module t|o the in|
|00000fe0| 74 65 72 70 72 65 74 65 | 72 2c 20 65 69 74 68 65 |terprete|r, eithe|
|00000ff0| 72 20 74 6f 0d 70 65 72 | 66 6f 72 6d 20 63 72 69 |r to.per|form cri|
|00001000| 74 69 63 61 6c 20 6f 70 | 65 72 61 74 69 6f 6e 73 |tical op|erations|
|00001010| 20 61 74 20 6d 61 78 69 | 6d 75 6d 20 73 70 65 65 | at maxi|mum spee|
|00001020| 64 2c 20 6f 72 20 74 6f | 20 6c 69 6e 6b 20 50 79 |d, or to| link Py|
|00001030| 74 68 6f 6e 0d 70 72 6f | 67 72 61 6d 73 20 74 6f |thon.pro|grams to|
|00001040| 20 6c 69 62 72 61 72 69 | 65 73 20 74 68 61 74 20 | librari|es that |
|00001050| 6d 61 79 20 6f 6e 6c 79 | 20 62 65 20 61 76 61 69 |may only| be avai|
|00001060| 6c 61 62 6c 65 20 69 6e | 20 62 69 6e 61 72 79 20 |lable in| binary |
|00001070| 66 6f 72 6d 20 28 73 75 | 63 68 0d 61 73 20 61 20 |form (su|ch.as a |
|00001080| 76 65 6e 64 6f 72 2d 73 | 70 65 63 69 66 69 63 20 |vendor-s|pecific |
|00001090| 67 72 61 70 68 69 63 73 | 20 6c 69 62 72 61 72 79 |graphics| library|
|000010a0| 29 2e 20 20 4f 6e 63 65 | 20 79 6f 75 20 61 72 65 |). Once| you are|
|000010b0| 20 72 65 61 6c 6c 79 20 | 68 6f 6f 6b 65 64 2c 0d | really |hooked,.|
|000010c0| 79 6f 75 20 63 61 6e 20 | 6c 69 6e 6b 20 74 68 65 |you can |link the|
|000010d0| 20 50 79 74 68 6f 6e 20 | 69 6e 74 65 72 70 72 65 | Python |interpre|
|000010e0| 74 65 72 20 69 6e 74 6f | 20 61 6e 20 61 70 70 6c |ter into| an appl|
|000010f0| 69 63 61 74 69 6f 6e 20 | 77 72 69 74 74 65 6e 20 |ication |written |
|00001100| 69 6e 20 43 0d 61 6e 64 | 20 75 73 65 20 69 74 20 |in C.and| use it |
|00001110| 61 73 20 61 6e 20 65 78 | 74 65 6e 73 69 6f 6e 20 |as an ex|tension |
|00001120| 6f 72 20 63 6f 6d 6d 61 | 6e 64 20 6c 61 6e 67 75 |or comma|nd langu|
|00001130| 61 67 65 20 66 6f 72 20 | 74 68 61 74 20 61 70 70 |age for |that app|
|00001140| 6c 69 63 61 74 69 6f 6e | 2e 0d 0d 42 79 20 74 68 |lication|...By th|
|00001150| 65 20 77 61 79 2c 20 74 | 68 65 20 6c 61 6e 67 75 |e way, t|he langu|
|00001160| 61 67 65 20 69 73 20 6e | 61 6d 65 64 20 61 66 74 |age is n|amed aft|
|00001170| 65 72 20 74 68 65 20 42 | 42 43 20 73 68 6f 77 20 |er the B|BC show |
|00001180| 60 60 4d 6f 6e 74 79 0d | 50 79 74 68 6f 6e 27 73 |``Monty.|Python's|
|00001190| 20 46 6c 79 69 6e 67 20 | 43 69 72 63 75 73 27 27 | Flying |Circus''|
|000011a0| 20 61 6e 64 20 68 61 73 | 20 6e 6f 74 68 69 6e 67 | and has| nothing|
|000011b0| 20 74 6f 20 64 6f 20 77 | 69 74 68 20 6e 61 73 74 | to do w|ith nast|
|000011c0| 79 20 72 65 70 74 69 6c | 65 73 2e 2e 2e 0d 0d 5c |y reptil|es.....\|
|000011d0| 73 65 63 74 69 6f 6e 7b | 57 68 65 72 65 20 46 72 |section{|Where Fr|
|000011e0| 6f 6d 20 48 65 72 65 7d | 0d 0d 4e 6f 77 20 74 68 |om Here}|..Now th|
|000011f0| 61 74 20 79 6f 75 20 61 | 72 65 20 61 6c 6c 20 65 |at you a|re all e|
|00001200| 78 63 69 74 65 64 20 61 | 62 6f 75 74 20 50 79 74 |xcited a|bout Pyt|
|00001210| 68 6f 6e 2c 20 79 6f 75 | 27 6c 6c 20 77 61 6e 74 |hon, you|'ll want|
|00001220| 20 74 6f 20 65 78 61 6d | 69 6e 65 20 69 74 0d 69 | to exam|ine it.i|
|00001230| 6e 20 73 6f 6d 65 20 6d | 6f 72 65 20 64 65 74 61 |n some m|ore deta|
|00001240| 69 6c 2e 20 20 53 69 6e | 63 65 20 74 68 65 20 62 |il. Sin|ce the b|
|00001250| 65 73 74 20 77 61 79 20 | 74 6f 20 6c 65 61 72 6e |est way |to learn|
|00001260| 20 61 20 6c 61 6e 67 75 | 61 67 65 20 69 73 0d 75 | a langu|age is.u|
|00001270| 73 69 6e 67 20 69 74 2c | 20 79 6f 75 20 61 72 65 |sing it,| you are|
|00001280| 20 69 6e 76 69 74 65 64 | 20 68 65 72 65 20 74 6f | invited| here to|
|00001290| 20 64 6f 20 73 6f 2e 0d | 0d 49 6e 20 74 68 65 20 | do so..|.In the |
|000012a0| 6e 65 78 74 20 63 68 61 | 70 74 65 72 2c 20 74 68 |next cha|pter, th|
|000012b0| 65 20 6d 65 63 68 61 6e | 69 63 73 20 6f 66 20 75 |e mechan|ics of u|
|000012c0| 73 69 6e 67 20 74 68 65 | 20 69 6e 74 65 72 70 72 |sing the| interpr|
|000012d0| 65 74 65 72 20 61 72 65 | 0d 65 78 70 6c 61 69 6e |eter are|.explain|
|000012e0| 65 64 2e 20 20 54 68 69 | 73 20 69 73 20 72 61 74 |ed. Thi|s is rat|
|000012f0| 68 65 72 20 6d 75 6e 64 | 61 6e 65 20 69 6e 66 6f |her mund|ane info|
|00001300| 72 6d 61 74 69 6f 6e 2c | 20 62 75 74 20 65 73 73 |rmation,| but ess|
|00001310| 65 6e 74 69 61 6c 20 66 | 6f 72 0d 74 72 79 69 6e |ential f|or.tryin|
|00001320| 67 20 6f 75 74 20 74 68 | 65 20 65 78 61 6d 70 6c |g out th|e exampl|
|00001330| 65 73 20 73 68 6f 77 6e | 20 6c 61 74 65 72 2e 0d |es shown| later..|
|00001340| 0d 54 68 65 20 72 65 73 | 74 20 6f 66 20 74 68 65 |.The res|t of the|
|00001350| 20 74 75 74 6f 72 69 61 | 6c 20 69 6e 74 72 6f 64 | tutoria|l introd|
|00001360| 75 63 65 73 20 76 61 72 | 69 6f 75 73 20 66 65 61 |uces var|ious fea|
|00001370| 74 75 72 65 73 20 6f 66 | 20 74 68 65 20 50 79 74 |tures of| the Pyt|
|00001380| 68 6f 6e 0d 6c 61 6e 67 | 75 61 67 65 20 61 6e 64 |hon.lang|uage and|
|00001390| 20 73 79 73 74 65 6d 20 | 74 68 6f 75 67 68 20 65 | system |though e|
|000013a0| 78 61 6d 70 6c 65 73 2c | 20 62 65 67 69 6e 6e 69 |xamples,| beginni|
|000013b0| 6e 67 20 77 69 74 68 20 | 73 69 6d 70 6c 65 0d 65 |ng with |simple.e|
|000013c0| 78 70 72 65 73 73 69 6f | 6e 73 2c 20 73 74 61 74 |xpressio|ns, stat|
|000013d0| 65 6d 65 6e 74 73 20 61 | 6e 64 20 64 61 74 61 20 |ements a|nd data |
|000013e0| 74 79 70 65 73 2c 20 74 | 68 72 6f 75 67 68 20 66 |types, t|hrough f|
|000013f0| 75 6e 63 74 69 6f 6e 73 | 20 61 6e 64 20 6d 6f 64 |unctions| and mod|
|00001400| 75 6c 65 73 2c 0d 61 6e | 64 20 66 69 6e 61 6c 6c |ules,.an|d finall|
|00001410| 79 20 74 6f 75 63 68 69 | 6e 67 20 75 70 6f 6e 20 |y touchi|ng upon |
|00001420| 61 64 76 61 6e 63 65 64 | 20 63 6f 6e 63 65 70 74 |advanced| concept|
|00001430| 73 20 6c 69 6b 65 20 65 | 78 63 65 70 74 69 6f 6e |s like e|xception|
|00001440| 73 0d 61 6e 64 20 75 73 | 65 72 2d 64 65 66 69 6e |s.and us|er-defin|
|00001450| 65 64 20 63 6c 61 73 73 | 65 73 2e 0d 0d 57 68 65 |ed class|es...Whe|
|00001460| 6e 20 79 6f 75 27 72 65 | 20 74 68 72 6f 75 67 68 |n you're| through|
|00001470| 20 77 69 74 68 20 74 68 | 65 20 74 75 74 6f 72 69 | with th|e tutori|
|00001480| 61 6c 20 28 6f 72 20 6a | 75 73 74 20 67 65 74 74 |al (or j|ust gett|
|00001490| 69 6e 67 20 62 6f 72 65 | 64 29 2c 20 79 6f 75 0d |ing bore|d), you.|
|000014a0| 73 68 6f 75 6c 64 20 72 | 65 61 64 20 74 68 65 20 |should r|ead the |
|000014b0| 4c 69 62 72 61 72 79 20 | 52 65 66 65 72 65 6e 63 |Library |Referenc|
|000014c0| 65 2c 20 77 68 69 63 68 | 20 67 69 76 65 73 20 63 |e, which| gives c|
|000014d0| 6f 6d 70 6c 65 74 65 20 | 28 74 68 6f 75 67 68 20 |omplete |(though |
|000014e0| 74 65 72 73 65 29 0d 72 | 65 66 65 72 65 6e 63 65 |terse).r|eference|
|000014f0| 20 6d 61 74 65 72 69 61 | 6c 20 61 62 6f 75 74 20 | materia|l about |
|00001500| 62 75 69 6c 74 2d 69 6e | 20 61 6e 64 20 73 74 61 |built-in| and sta|
|00001510| 6e 64 61 72 64 20 74 79 | 70 65 73 2c 20 66 75 6e |ndard ty|pes, fun|
|00001520| 63 74 69 6f 6e 73 20 61 | 6e 64 0d 6d 6f 64 75 6c |ctions a|nd.modul|
|00001530| 65 73 20 74 68 61 74 20 | 63 61 6e 20 73 61 76 65 |es that |can save|
|00001540| 20 79 6f 75 20 61 20 6c | 6f 74 20 6f 66 20 74 69 | you a l|ot of ti|
|00001550| 6d 65 20 77 68 65 6e 20 | 77 72 69 74 69 6e 67 20 |me when |writing |
|00001560| 50 79 74 68 6f 6e 20 70 | 72 6f 67 72 61 6d 73 2e |Python p|rograms.|
|00001570| 0d 0d 0d 5c 63 68 61 70 | 74 65 72 7b 55 73 69 6e |...\chap|ter{Usin|
|00001580| 67 20 74 68 65 20 50 79 | 74 68 6f 6e 20 49 6e 74 |g the Py|thon Int|
|00001590| 65 72 70 72 65 74 65 72 | 7d 0d 0d 5c 73 65 63 74 |erpreter|}..\sect|
|000015a0| 69 6f 6e 7b 49 6e 76 6f | 6b 69 6e 67 20 74 68 65 |ion{Invo|king the|
|000015b0| 20 49 6e 74 65 72 70 72 | 65 74 65 72 7d 0d 0d 54 | Interpr|eter}..T|
|000015c0| 68 65 20 50 79 74 68 6f | 6e 20 69 6e 74 65 72 70 |he Pytho|n interp|
|000015d0| 72 65 74 65 72 20 69 73 | 20 75 73 75 61 6c 6c 79 |reter is| usually|
|000015e0| 20 69 6e 73 74 61 6c 6c | 65 64 20 61 73 20 7b 5c | install|ed as {\|
|000015f0| 74 74 20 2f 75 73 72 2f | 6c 6f 63 61 6c 2f 62 69 |tt /usr/|local/bi|
|00001600| 6e 2f 70 79 74 68 6f 6e | 7d 0d 6f 6e 20 74 68 6f |n/python|}.on tho|
|00001610| 73 65 20 6d 61 63 68 69 | 6e 65 73 20 77 68 65 72 |se machi|nes wher|
|00001620| 65 20 69 74 20 69 73 20 | 61 76 61 69 6c 61 62 6c |e it is |availabl|
|00001630| 65 3b 20 70 75 74 74 69 | 6e 67 20 7b 5c 74 74 20 |e; putti|ng {\tt |
|00001640| 2f 75 73 72 2f 6c 6f 63 | 61 6c 2f 62 69 6e 7d 20 |/usr/loc|al/bin} |
|00001650| 69 6e 0d 79 6f 75 72 20 | 7b 5c 55 4e 49 58 7d 20 |in.your |{\UNIX} |
|00001660| 73 68 65 6c 6c 27 73 20 | 73 65 61 72 63 68 20 70 |shell's |search p|
|00001670| 61 74 68 20 6d 61 6b 65 | 73 20 69 74 20 70 6f 73 |ath make|s it pos|
|00001680| 73 69 62 6c 65 20 74 6f | 20 73 74 61 72 74 20 69 |sible to| start i|
|00001690| 74 20 62 79 0d 74 79 70 | 69 6e 67 20 74 68 65 20 |t by.typ|ing the |
|000016a0| 63 6f 6d 6d 61 6e 64 0d | 0d 5c 62 63 6f 64 65 5c |command.|.\bcode\|
|000016b0| 62 65 67 69 6e 7b 76 65 | 72 62 61 74 69 6d 7d 0d |begin{ve|rbatim}.|
|000016c0| 70 79 74 68 6f 6e 0d 5c | 65 6e 64 7b 76 65 72 62 |python.\|end{verb|
|000016d0| 61 74 69 6d 7d 5c 65 63 | 6f 64 65 0d 25 0d 74 6f |atim}\ec|ode.%.to|
|000016e0| 20 74 68 65 20 73 68 65 | 6c 6c 2e 20 20 53 69 6e | the she|ll. Sin|
|000016f0| 63 65 20 74 68 65 20 63 | 68 6f 69 63 65 20 6f 66 |ce the c|hoice of|
|00001700| 20 74 68 65 20 64 69 72 | 65 63 74 6f 72 79 20 77 | the dir|ectory w|
|00001710| 68 65 72 65 20 74 68 65 | 20 69 6e 74 65 72 70 72 |here the| interpr|
|00001720| 65 74 65 72 0d 6c 69 76 | 65 73 20 69 73 20 61 6e |eter.liv|es is an|
|00001730| 20 69 6e 73 74 61 6c 6c | 61 74 69 6f 6e 20 6f 70 | install|ation op|
|00001740| 74 69 6f 6e 2c 20 6f 74 | 68 65 72 20 70 6c 61 63 |tion, ot|her plac|
|00001750| 65 73 20 61 72 65 20 70 | 6f 73 73 69 62 6c 65 3b |es are p|ossible;|
|00001760| 20 63 68 65 63 6b 20 77 | 69 74 68 0d 79 6f 75 72 | check w|ith.your|
|00001770| 20 6c 6f 63 61 6c 20 50 | 79 74 68 6f 6e 20 67 75 | local P|ython gu|
|00001780| 72 75 20 6f 72 20 73 79 | 73 74 65 6d 20 61 64 6d |ru or sy|stem adm|
|00001790| 69 6e 69 73 74 72 61 74 | 6f 72 2e 20 20 28 45 2e |inistrat|or. (E.|
|000017a0| 67 2e 2c 20 7b 5c 74 74 | 0d 2f 75 73 72 2f 6c 6f |g., {\tt|./usr/lo|
|000017b0| 63 61 6c 2f 70 79 74 68 | 6f 6e 7d 20 69 73 20 61 |cal/pyth|on} is a|
|000017c0| 20 70 6f 70 75 6c 61 72 | 20 61 6c 74 65 72 6e 61 | popular| alterna|
|000017d0| 74 69 76 65 20 6c 6f 63 | 61 74 69 6f 6e 2e 29 0d |tive loc|ation.).|
|000017e0| 0d 54 68 65 20 69 6e 74 | 65 72 70 72 65 74 65 72 |.The int|erpreter|
|000017f0| 20 6f 70 65 72 61 74 65 | 73 20 73 6f 6d 65 77 68 | operate|s somewh|
|00001800| 61 74 20 6c 69 6b 65 20 | 74 68 65 20 7b 5c 55 4e |at like |the {\UN|
|00001810| 49 58 7d 20 73 68 65 6c | 6c 3a 20 77 68 65 6e 20 |IX} shel|l: when |
|00001820| 63 61 6c 6c 65 64 0d 77 | 69 74 68 20 73 74 61 6e |called.w|ith stan|
|00001830| 64 61 72 64 20 69 6e 70 | 75 74 20 63 6f 6e 6e 65 |dard inp|ut conne|
|00001840| 63 74 65 64 20 74 6f 20 | 61 20 74 74 79 20 64 65 |cted to |a tty de|
|00001850| 76 69 63 65 2c 20 69 74 | 20 72 65 61 64 73 20 61 |vice, it| reads a|
|00001860| 6e 64 20 65 78 65 63 75 | 74 65 73 0d 63 6f 6d 6d |nd execu|tes.comm|
|00001870| 61 6e 64 73 20 69 6e 74 | 65 72 61 63 74 69 76 65 |ands int|eractive|
|00001880| 6c 79 3b 20 77 68 65 6e | 20 63 61 6c 6c 65 64 20 |ly; when| called |
|00001890| 77 69 74 68 20 61 20 66 | 69 6c 65 20 6e 61 6d 65 |with a f|ile name|
|000018a0| 20 61 72 67 75 6d 65 6e | 74 20 6f 72 20 77 69 74 | argumen|t or wit|
|000018b0| 68 0d 61 20 66 69 6c 65 | 20 61 73 20 73 74 61 6e |h.a file| as stan|
|000018c0| 64 61 72 64 20 69 6e 70 | 75 74 2c 20 69 74 20 72 |dard inp|ut, it r|
|000018d0| 65 61 64 73 20 61 6e 64 | 20 65 78 65 63 75 74 65 |eads and| execute|
|000018e0| 73 20 61 20 7b 5c 65 6d | 20 73 63 72 69 70 74 7d |s a {\em| script}|
|000018f0| 20 66 72 6f 6d 0d 74 68 | 61 74 20 66 69 6c 65 2e | from.th|at file.|
|00001900| 0d 0d 41 20 74 68 69 72 | 64 20 77 61 79 20 6f 66 |..A thir|d way of|
|00001910| 20 73 74 61 72 74 69 6e | 67 20 74 68 65 20 69 6e | startin|g the in|
|00001920| 74 65 72 70 72 65 74 65 | 72 20 69 73 0d 60 60 7b |terprete|r is.``{|
|00001930| 5c 74 74 20 70 79 74 68 | 6f 6e 20 2d 63 20 63 6f |\tt pyth|on -c co|
|00001940| 6d 6d 61 6e 64 20 5b 61 | 72 67 5d 20 2e 2e 2e 7d |mmand [a|rg] ...}|
|00001950| 27 27 2c 20 77 68 69 63 | 68 0d 65 78 65 63 75 74 |'', whic|h.execut|
|00001960| 65 73 20 74 68 65 20 73 | 74 61 74 65 6d 65 6e 74 |es the s|tatement|
|00001970| 28 73 29 20 69 6e 20 7b | 5c 74 74 20 63 6f 6d 6d |(s) in {|\tt comm|
|00001980| 61 6e 64 7d 2c 20 61 6e | 61 6c 6f 67 6f 75 73 20 |and}, an|alogous |
|00001990| 74 6f 20 74 68 65 20 73 | 68 65 6c 6c 27 73 0d 7b |to the s|hell's.{|
|000019a0| 5c 74 74 20 2d 63 7d 20 | 6f 70 74 69 6f 6e 2e 20 |\tt -c} |option. |
|000019b0| 20 53 69 6e 63 65 20 50 | 79 74 68 6f 6e 20 73 74 | Since P|ython st|
|000019c0| 61 74 65 6d 65 6e 74 73 | 20 6f 66 74 65 6e 20 63 |atements| often c|
|000019d0| 6f 6e 74 61 69 6e 20 73 | 70 61 63 65 73 20 6f 72 |ontain s|paces or|
|000019e0| 20 6f 74 68 65 72 0d 63 | 68 61 72 61 63 74 65 72 | other.c|haracter|
|000019f0| 73 20 74 68 61 74 20 61 | 72 65 20 73 70 65 63 69 |s that a|re speci|
|00001a00| 61 6c 20 74 6f 20 74 68 | 65 20 73 68 65 6c 6c 2c |al to th|e shell,|
|00001a10| 20 69 74 20 69 73 20 62 | 65 73 74 20 74 6f 20 71 | it is b|est to q|
|00001a20| 75 6f 74 65 20 7b 5c 74 | 74 0d 63 6f 6d 6d 61 6e |uote {\t|t.comman|
|00001a30| 64 7d 20 69 6e 20 69 74 | 73 20 65 6e 74 69 72 65 |d} in it|s entire|
|00001a40| 74 79 20 77 69 74 68 20 | 64 6f 75 62 6c 65 20 71 |ty with |double q|
|00001a50| 75 6f 74 65 73 2e 0d 0d | 4e 6f 74 65 20 74 68 61 |uotes...|Note tha|
|00001a60| 74 20 74 68 65 72 65 20 | 69 73 20 61 20 64 69 66 |t there |is a dif|
|00001a70| 66 65 72 65 6e 63 65 20 | 62 65 74 77 65 65 6e 20 |ference |between |
|00001a80| 60 60 7b 5c 74 74 20 70 | 79 74 68 6f 6e 20 66 69 |``{\tt p|ython fi|
|00001a90| 6c 65 7d 27 27 20 61 6e | 64 0d 60 60 7b 5c 74 74 |le}'' an|d.``{\tt|
|00001aa0| 20 70 79 74 68 6f 6e 20 | 24 3c 24 66 69 6c 65 7d | python |$<$file}|
|00001ab0| 27 27 2e 20 20 49 6e 20 | 74 68 65 20 6c 61 74 74 |''. In |the latt|
|00001ac0| 65 72 20 63 61 73 65 2c | 20 69 6e 70 75 74 20 72 |er case,| input r|
|00001ad0| 65 71 75 65 73 74 73 20 | 66 72 6f 6d 20 74 68 65 |equests |from the|
|00001ae0| 0d 70 72 6f 67 72 61 6d | 2c 20 73 75 63 68 20 61 |.program|, such a|
|00001af0| 73 20 63 61 6c 6c 73 20 | 74 6f 20 7b 5c 74 74 20 |s calls |to {\tt |
|00001b00| 69 6e 70 75 74 28 29 7d | 20 61 6e 64 20 7b 5c 74 |input()}| and {\t|
|00001b10| 74 20 72 61 77 5f 69 6e | 70 75 74 28 29 7d 2c 20 |t raw_in|put()}, |
|00001b20| 61 72 65 0d 73 61 74 69 | 73 66 69 65 64 20 66 72 |are.sati|sfied fr|
|00001b30| 6f 6d 20 7b 5c 65 6d 20 | 66 69 6c 65 7d 2e 20 20 |om {\em |file}. |
|00001b40| 53 69 6e 63 65 20 74 68 | 69 73 20 66 69 6c 65 20 |Since th|is file |
|00001b50| 68 61 73 20 61 6c 72 65 | 61 64 79 20 62 65 65 6e |has alre|ady been|
|00001b60| 20 72 65 61 64 0d 75 6e | 74 69 6c 20 74 68 65 20 | read.un|til the |
|00001b70| 65 6e 64 20 62 79 20 74 | 68 65 20 70 61 72 73 65 |end by t|he parse|
|00001b80| 72 20 62 65 66 6f 72 65 | 20 74 68 65 20 70 72 6f |r before| the pro|
|00001b90| 67 72 61 6d 20 73 74 61 | 72 74 73 20 65 78 65 63 |gram sta|rts exec|
|00001ba0| 75 74 69 6e 67 2c 20 74 | 68 65 0d 70 72 6f 67 72 |uting, t|he.progr|
|00001bb0| 61 6d 20 77 69 6c 6c 20 | 65 6e 63 6f 75 6e 74 65 |am will |encounte|
|00001bc0| 72 20 45 4f 46 20 69 6d | 6d 65 64 69 61 74 65 6c |r EOF im|mediatel|
|00001bd0| 79 2e 20 20 49 6e 20 74 | 68 65 20 66 6f 72 6d 65 |y. In t|he forme|
|00001be0| 72 20 63 61 73 65 20 28 | 77 68 69 63 68 20 69 73 |r case (|which is|
|00001bf0| 0d 75 73 75 61 6c 6c 79 | 20 77 68 61 74 20 79 6f |.usually| what yo|
|00001c00| 75 20 77 61 6e 74 29 20 | 74 68 65 79 20 61 72 65 |u want) |they are|
|00001c10| 20 73 61 74 69 73 66 69 | 65 64 20 66 72 6f 6d 20 | satisfi|ed from |
|00001c20| 77 68 61 74 65 76 65 72 | 20 66 69 6c 65 20 6f 72 |whatever| file or|
|00001c30| 20 64 65 76 69 63 65 0d | 69 73 20 63 6f 6e 6e 65 | device.|is conne|
|00001c40| 63 74 65 64 20 74 6f 20 | 73 74 61 6e 64 61 72 64 |cted to |standard|
|00001c50| 20 69 6e 70 75 74 20 6f | 66 20 74 68 65 20 50 79 | input o|f the Py|
|00001c60| 74 68 6f 6e 20 69 6e 74 | 65 72 70 72 65 74 65 72 |thon int|erpreter|
|00001c70| 2e 0d 0d 57 68 65 6e 20 | 61 20 73 63 72 69 70 74 |...When |a script|
|00001c80| 20 66 69 6c 65 20 69 73 | 20 75 73 65 64 2c 20 69 | file is| used, i|
|00001c90| 74 20 69 73 20 73 6f 6d | 65 74 69 6d 65 73 20 75 |t is som|etimes u|
|00001ca0| 73 65 66 75 6c 20 74 6f | 20 62 65 20 61 62 6c 65 |seful to| be able|
|00001cb0| 20 74 6f 20 72 75 6e 0d | 74 68 65 20 73 63 72 69 | to run.|the scri|
|00001cc0| 70 74 20 61 6e 64 20 65 | 6e 74 65 72 20 69 6e 74 |pt and e|nter int|
|00001cd0| 65 72 61 63 74 69 76 65 | 20 6d 6f 64 65 20 61 66 |eractive| mode af|
|00001ce0| 74 65 72 77 61 72 64 73 | 2e 20 20 54 68 69 73 20 |terwards|. This |
|00001cf0| 63 61 6e 20 62 65 20 64 | 6f 6e 65 20 62 79 0d 70 |can be d|one by.p|
|00001d00| 61 73 73 69 6e 67 20 7b | 5c 74 74 20 2d 69 7d 20 |assing {|\tt -i} |
|00001d10| 62 65 66 6f 72 65 20 74 | 68 65 20 73 63 72 69 70 |before t|he scrip|
|00001d20| 74 2e 20 20 28 54 68 69 | 73 20 64 6f 65 73 20 6e |t. (Thi|s does n|
|00001d30| 6f 74 20 77 6f 72 6b 20 | 69 66 20 74 68 65 20 73 |ot work |if the s|
|00001d40| 63 72 69 70 74 0d 69 73 | 20 72 65 61 64 20 66 72 |cript.is| read fr|
|00001d50| 6f 6d 20 73 74 61 6e 64 | 61 72 64 20 69 6e 70 75 |om stand|ard inpu|
|00001d60| 74 2c 20 66 6f 72 20 74 | 68 65 20 73 61 6d 65 20 |t, for t|he same |
|00001d70| 72 65 61 73 6f 6e 20 61 | 73 20 65 78 70 6c 61 69 |reason a|s explai|
|00001d80| 6e 65 64 20 69 6e 20 74 | 68 65 0d 70 72 65 76 69 |ned in t|he.previ|
|00001d90| 6f 75 73 20 70 61 72 61 | 67 72 61 70 68 2e 29 0d |ous para|graph.).|
|00001da0| 0d 5c 73 75 62 73 65 63 | 74 69 6f 6e 7b 41 72 67 |.\subsec|tion{Arg|
|00001db0| 75 6d 65 6e 74 20 50 61 | 73 73 69 6e 67 7d 0d 0d |ument Pa|ssing}..|
|00001dc0| 57 68 65 6e 20 6b 6e 6f | 77 6e 20 74 6f 20 74 68 |When kno|wn to th|
|00001dd0| 65 20 69 6e 74 65 72 70 | 72 65 74 65 72 2c 20 74 |e interp|reter, t|
|00001de0| 68 65 20 73 63 72 69 70 | 74 20 6e 61 6d 65 20 61 |he scrip|t name a|
|00001df0| 6e 64 20 61 64 64 69 74 | 69 6f 6e 61 6c 0d 61 72 |nd addit|ional.ar|
|00001e00| 67 75 6d 65 6e 74 73 20 | 74 68 65 72 65 61 66 74 |guments |thereaft|
|00001e10| 65 72 20 61 72 65 20 70 | 61 73 73 65 64 20 74 6f |er are p|assed to|
|00001e20| 20 74 68 65 20 73 63 72 | 69 70 74 20 69 6e 20 74 | the scr|ipt in t|
|00001e30| 68 65 20 76 61 72 69 61 | 62 6c 65 20 7b 5c 74 74 |he varia|ble {\tt|
|00001e40| 0d 73 79 73 2e 61 72 67 | 76 7d 2c 20 77 68 69 63 |.sys.arg|v}, whic|
|00001e50| 68 20 69 73 20 61 20 6c | 69 73 74 20 6f 66 20 73 |h is a l|ist of s|
|00001e60| 74 72 69 6e 67 73 2e 20 | 20 49 74 73 20 6c 65 6e |trings. | Its len|
|00001e70| 67 74 68 20 69 73 20 61 | 74 20 6c 65 61 73 74 20 |gth is a|t least |
|00001e80| 6f 6e 65 3b 0d 77 68 65 | 6e 20 6e 6f 20 73 63 72 |one;.whe|n no scr|
|00001e90| 69 70 74 20 61 6e 64 20 | 6e 6f 20 61 72 67 75 6d |ipt and |no argum|
|00001ea0| 65 6e 74 73 20 61 72 65 | 20 67 69 76 65 6e 2c 20 |ents are| given, |
|00001eb0| 7b 5c 74 74 20 73 79 73 | 2e 61 72 67 76 5b 30 5d |{\tt sys|.argv[0]|
|00001ec0| 7d 20 69 73 20 61 6e 0d | 65 6d 70 74 79 20 73 74 |} is an.|empty st|
|00001ed0| 72 69 6e 67 2e 20 20 57 | 68 65 6e 20 74 68 65 20 |ring. W|hen the |
|00001ee0| 73 63 72 69 70 74 20 6e | 61 6d 65 20 69 73 20 67 |script n|ame is g|
|00001ef0| 69 76 65 6e 20 61 73 20 | 7b 5c 74 74 20 27 2d 27 |iven as |{\tt '-'|
|00001f00| 7d 20 28 6d 65 61 6e 69 | 6e 67 0d 73 74 61 6e 64 |} (meani|ng.stand|
|00001f10| 61 72 64 20 69 6e 70 75 | 74 29 2c 20 7b 5c 74 74 |ard inpu|t), {\tt|
|00001f20| 20 73 79 73 2e 61 72 67 | 76 5b 30 5d 7d 20 69 73 | sys.arg|v[0]} is|
|00001f30| 20 73 65 74 20 74 6f 20 | 7b 5c 74 74 20 27 2d 27 | set to |{\tt '-'|
|00001f40| 7d 2e 20 20 57 68 65 6e | 20 7b 5c 74 74 20 2d 63 |}. When| {\tt -c|
|00001f50| 0d 63 6f 6d 6d 61 6e 64 | 7d 20 69 73 20 75 73 65 |.command|} is use|
|00001f60| 64 2c 20 7b 5c 74 74 20 | 73 79 73 2e 61 72 67 76 |d, {\tt |sys.argv|
|00001f70| 5b 30 5d 7d 20 69 73 20 | 73 65 74 20 74 6f 20 7b |[0]} is |set to {|
|00001f80| 5c 74 74 20 27 2d 63 27 | 7d 2e 20 20 4f 70 74 69 |\tt '-c'|}. Opti|
|00001f90| 6f 6e 73 0d 66 6f 75 6e | 64 20 61 66 74 65 72 20 |ons.foun|d after |
|00001fa0| 7b 5c 74 74 20 2d 63 20 | 63 6f 6d 6d 61 6e 64 7d |{\tt -c |command}|
|00001fb0| 20 61 72 65 20 6e 6f 74 | 20 63 6f 6e 73 75 6d 65 | are not| consume|
|00001fc0| 64 20 62 79 20 74 68 65 | 20 50 79 74 68 6f 6e 0d |d by the| Python.|
|00001fd0| 69 6e 74 65 72 70 72 65 | 74 65 72 27 73 20 6f 70 |interpre|ter's op|
|00001fe0| 74 69 6f 6e 20 70 72 6f | 63 65 73 73 69 6e 67 20 |tion pro|cessing |
|00001ff0| 62 75 74 20 6c 65 66 74 | 20 69 6e 20 7b 5c 74 74 |but left| in {\tt|
|00002000| 20 73 79 73 2e 61 72 67 | 76 7d 20 66 6f 72 20 74 | sys.arg|v} for t|
|00002010| 68 65 0d 63 6f 6d 6d 61 | 6e 64 20 74 6f 20 68 61 |he.comma|nd to ha|
|00002020| 6e 64 6c 65 2e 0d 0d 5c | 73 75 62 73 65 63 74 69 |ndle...\|subsecti|
|00002030| 6f 6e 7b 49 6e 74 65 72 | 61 63 74 69 76 65 20 4d |on{Inter|active M|
|00002040| 6f 64 65 7d 0d 0d 57 68 | 65 6e 20 63 6f 6d 6d 61 |ode}..Wh|en comma|
|00002050| 6e 64 73 20 61 72 65 20 | 72 65 61 64 20 66 72 6f |nds are |read fro|
|00002060| 6d 20 61 20 74 74 79 2c | 20 74 68 65 20 69 6e 74 |m a tty,| the int|
|00002070| 65 72 70 72 65 74 65 72 | 20 69 73 20 73 61 69 64 |erpreter| is said|
|00002080| 20 74 6f 20 62 65 20 69 | 6e 0d 7b 5c 65 6d 20 69 | to be i|n.{\em i|
|00002090| 6e 74 65 72 61 63 74 69 | 76 65 5c 20 6d 6f 64 65 |nteracti|ve\ mode|
|000020a0| 7d 2e 20 20 49 6e 20 74 | 68 69 73 20 6d 6f 64 65 |}. In t|his mode|
|000020b0| 20 69 74 20 70 72 6f 6d | 70 74 73 20 66 6f 72 20 | it prom|pts for |
|000020c0| 74 68 65 20 6e 65 78 74 | 20 63 6f 6d 6d 61 6e 64 |the next| command|
|000020d0| 0d 77 69 74 68 20 74 68 | 65 20 7b 5c 65 6d 20 70 |.with th|e {\em p|
|000020e0| 72 69 6d 61 72 79 5c 20 | 70 72 6f 6d 70 74 7d 2c |rimary\ |prompt},|
|000020f0| 20 75 73 75 61 6c 6c 79 | 20 74 68 72 65 65 20 67 | usually| three g|
|00002100| 72 65 61 74 65 72 2d 74 | 68 61 6e 20 73 69 67 6e |reater-t|han sign|
|00002110| 73 20 28 7b 5c 74 74 0d | 3e 3e 3e 7d 29 3b 20 66 |s ({\tt.|>>>}); f|
|00002120| 6f 72 20 63 6f 6e 74 69 | 6e 75 61 74 69 6f 6e 20 |or conti|nuation |
|00002130| 6c 69 6e 65 73 20 69 74 | 20 70 72 6f 6d 70 74 73 |lines it| prompts|
|00002140| 20 77 69 74 68 20 74 68 | 65 0d 7b 5c 65 6d 20 73 | with th|e.{\em s|
|00002150| 65 63 6f 6e 64 61 72 79 | 5c 20 70 72 6f 6d 70 74 |econdary|\ prompt|
|00002160| 7d 2c 0d 62 79 20 64 65 | 66 61 75 6c 74 20 74 68 |},.by de|fault th|
|00002170| 72 65 65 20 64 6f 74 73 | 20 28 7b 5c 74 74 20 2e |ree dots| ({\tt .|
|00002180| 2e 2e 7d 29 2e 20 20 54 | 79 70 69 6e 67 20 61 6e |..}). T|yping an|
|00002190| 20 45 4f 46 20 28 43 6f | 6e 74 72 6f 6c 2d 44 29 | EOF (Co|ntrol-D)|
|000021a0| 20 0d 61 74 20 74 68 65 | 20 70 72 69 6d 61 72 79 | .at the| primary|
|000021b0| 20 70 72 6f 6d 70 74 20 | 63 61 75 73 65 73 20 74 | prompt |causes t|
|000021c0| 68 65 20 69 6e 74 65 72 | 70 72 65 74 65 72 20 74 |he inter|preter t|
|000021d0| 6f 20 65 78 69 74 20 77 | 69 74 68 20 61 20 7a 65 |o exit w|ith a ze|
|000021e0| 72 6f 20 65 78 69 74 0d | 73 74 61 74 75 73 2e 0d |ro exit.|status..|
|000021f0| 0d 54 68 65 20 69 6e 74 | 65 72 70 72 65 74 65 72 |.The int|erpreter|
|00002200| 20 70 72 69 6e 74 73 20 | 61 20 77 65 6c 63 6f 6d | prints |a welcom|
|00002210| 65 20 6d 65 73 73 61 67 | 65 20 73 74 61 74 69 6e |e messag|e statin|
|00002220| 67 20 69 74 73 20 76 65 | 72 73 69 6f 6e 20 6e 75 |g its ve|rsion nu|
|00002230| 6d 62 65 72 0d 61 6e 64 | 20 61 20 63 6f 70 79 72 |mber.and| a copyr|
|00002240| 69 67 68 74 20 6e 6f 74 | 69 63 65 20 62 65 66 6f |ight not|ice befo|
|00002250| 72 65 20 70 72 69 6e 74 | 69 6e 67 20 74 68 65 20 |re print|ing the |
|00002260| 66 69 72 73 74 20 70 72 | 6f 6d 70 74 2c 20 65 2e |first pr|ompt, e.|
|00002270| 67 2e 3a 0d 0d 5c 62 63 | 6f 64 65 5c 62 65 67 69 |g.:..\bc|ode\begi|
|00002280| 6e 7b 76 65 72 62 61 74 | 69 6d 7d 0d 70 79 74 68 |n{verbat|im}.pyth|
|00002290| 6f 6e 0d 50 79 74 68 6f | 6e 20 31 2e 33 20 28 4f |on.Pytho|n 1.3 (O|
|000022a0| 63 74 20 31 33 20 31 39 | 39 35 29 0d 43 6f 70 79 |ct 13 19|95).Copy|
|000022b0| 72 69 67 68 74 20 31 39 | 39 31 2d 31 39 39 35 20 |right 19|91-1995 |
|000022c0| 53 74 69 63 68 74 69 6e | 67 20 4d 61 74 68 65 6d |Stichtin|g Mathem|
|000022d0| 61 74 69 73 63 68 20 43 | 65 6e 74 72 75 6d 2c 20 |atisch C|entrum, |
|000022e0| 41 6d 73 74 65 72 64 61 | 6d 0d 3e 3e 3e 0d 5c 65 |Amsterda|m.>>>.\e|
|000022f0| 6e 64 7b 76 65 72 62 61 | 74 69 6d 7d 5c 65 63 6f |nd{verba|tim}\eco|
|00002300| 64 65 0d 0d 5c 73 65 63 | 74 69 6f 6e 7b 54 68 65 |de..\sec|tion{The|
|00002310| 20 49 6e 74 65 72 70 72 | 65 74 65 72 20 61 6e 64 | Interpr|eter and|
|00002320| 20 69 74 73 20 45 6e 76 | 69 72 6f 6e 6d 65 6e 74 | its Env|ironment|
|00002330| 7d 0d 0d 5c 73 75 62 73 | 65 63 74 69 6f 6e 7b 45 |}..\subs|ection{E|
|00002340| 72 72 6f 72 20 48 61 6e | 64 6c 69 6e 67 7d 0d 0d |rror Han|dling}..|
|00002350| 57 68 65 6e 20 61 6e 20 | 65 72 72 6f 72 20 6f 63 |When an |error oc|
|00002360| 63 75 72 73 2c 20 74 68 | 65 20 69 6e 74 65 72 70 |curs, th|e interp|
|00002370| 72 65 74 65 72 20 70 72 | 69 6e 74 73 20 61 6e 20 |reter pr|ints an |
|00002380| 65 72 72 6f 72 0d 6d 65 | 73 73 61 67 65 20 61 6e |error.me|ssage an|
|00002390| 64 20 61 20 73 74 61 63 | 6b 20 74 72 61 63 65 2e |d a stac|k trace.|
|000023a0| 20 20 49 6e 20 69 6e 74 | 65 72 61 63 74 69 76 65 | In int|eractive|
|000023b0| 20 6d 6f 64 65 2c 20 69 | 74 20 74 68 65 6e 20 72 | mode, i|t then r|
|000023c0| 65 74 75 72 6e 73 20 74 | 6f 0d 74 68 65 20 70 72 |eturns t|o.the pr|
|000023d0| 69 6d 61 72 79 20 70 72 | 6f 6d 70 74 3b 20 77 68 |imary pr|ompt; wh|
|000023e0| 65 6e 20 69 6e 70 75 74 | 20 63 61 6d 65 20 66 72 |en input| came fr|
|000023f0| 6f 6d 20 61 20 66 69 6c | 65 2c 20 69 74 20 65 78 |om a fil|e, it ex|
|00002400| 69 74 73 20 77 69 74 68 | 20 61 0d 6e 6f 6e 7a 65 |its with| a.nonze|
|00002410| 72 6f 20 65 78 69 74 20 | 73 74 61 74 75 73 20 61 |ro exit |status a|
|00002420| 66 74 65 72 20 70 72 69 | 6e 74 69 6e 67 0d 74 68 |fter pri|nting.th|
|00002430| 65 20 73 74 61 63 6b 20 | 74 72 61 63 65 2e 20 20 |e stack |trace. |
|00002440| 28 45 78 63 65 70 74 69 | 6f 6e 73 20 68 61 6e 64 |(Excepti|ons hand|
|00002450| 6c 65 64 20 62 79 20 61 | 6e 20 7b 5c 74 74 20 65 |led by a|n {\tt e|
|00002460| 78 63 65 70 74 7d 20 63 | 6c 61 75 73 65 20 69 6e |xcept} c|lause in|
|00002470| 20 61 0d 7b 5c 74 74 20 | 74 72 79 7d 20 73 74 61 | a.{\tt |try} sta|
|00002480| 74 65 6d 65 6e 74 20 61 | 72 65 20 6e 6f 74 20 65 |tement a|re not e|
|00002490| 72 72 6f 72 73 20 69 6e | 20 74 68 69 73 20 63 6f |rrors in| this co|
|000024a0| 6e 74 65 78 74 2e 29 20 | 20 53 6f 6d 65 20 65 72 |ntext.) | Some er|
|000024b0| 72 6f 72 73 20 61 72 65 | 0d 75 6e 63 6f 6e 64 69 |rors are|.uncondi|
|000024c0| 74 69 6f 6e 61 6c 6c 79 | 20 66 61 74 61 6c 20 61 |tionally| fatal a|
|000024d0| 6e 64 20 63 61 75 73 65 | 20 61 6e 20 65 78 69 74 |nd cause| an exit|
|000024e0| 20 77 69 74 68 20 61 20 | 6e 6f 6e 7a 65 72 6f 20 | with a |nonzero |
|000024f0| 65 78 69 74 3b 20 74 68 | 69 73 0d 61 70 70 6c 69 |exit; th|is.appli|
|00002500| 65 73 20 74 6f 20 69 6e | 74 65 72 6e 61 6c 20 69 |es to in|ternal i|
|00002510| 6e 63 6f 6e 73 69 73 74 | 65 6e 63 69 65 73 20 61 |nconsist|encies a|
|00002520| 6e 64 20 73 6f 6d 65 20 | 63 61 73 65 73 20 6f 66 |nd some |cases of|
|00002530| 20 72 75 6e 6e 69 6e 67 | 20 6f 75 74 20 6f 66 0d | running| out of.|
|00002540| 6d 65 6d 6f 72 79 2e 20 | 20 41 6c 6c 20 65 72 72 |memory. | All err|
|00002550| 6f 72 20 6d 65 73 73 61 | 67 65 73 20 61 72 65 20 |or messa|ges are |
|00002560| 77 72 69 74 74 65 6e 20 | 74 6f 20 74 68 65 20 73 |written |to the s|
|00002570| 74 61 6e 64 61 72 64 20 | 65 72 72 6f 72 20 73 74 |tandard |error st|
|00002580| 72 65 61 6d 3b 0d 6e 6f | 72 6d 61 6c 20 6f 75 74 |ream;.no|rmal out|
|00002590| 70 75 74 20 66 72 6f 6d | 20 74 68 65 20 65 78 65 |put from| the exe|
|000025a0| 63 75 74 65 64 20 63 6f | 6d 6d 61 6e 64 73 20 69 |cuted co|mmands i|
|000025b0| 73 20 77 72 69 74 74 65 | 6e 20 74 6f 20 73 74 61 |s writte|n to sta|
|000025c0| 6e 64 61 72 64 0d 6f 75 | 74 70 75 74 2e 0d 0d 54 |ndard.ou|tput...T|
|000025d0| 79 70 69 6e 67 20 74 68 | 65 20 69 6e 74 65 72 72 |yping th|e interr|
|000025e0| 75 70 74 20 63 68 61 72 | 61 63 74 65 72 20 28 75 |upt char|acter (u|
|000025f0| 73 75 61 6c 6c 79 20 43 | 6f 6e 74 72 6f 6c 2d 43 |sually C|ontrol-C|
|00002600| 20 6f 72 20 44 45 4c 29 | 20 74 6f 20 74 68 65 0d | or DEL)| to the.|
|00002610| 70 72 69 6d 61 72 79 20 | 6f 72 20 73 65 63 6f 6e |primary |or secon|
|00002620| 64 61 72 79 20 70 72 6f | 6d 70 74 20 63 61 6e 63 |dary pro|mpt canc|
|00002630| 65 6c 73 20 74 68 65 20 | 69 6e 70 75 74 20 61 6e |els the |input an|
|00002640| 64 20 72 65 74 75 72 6e | 73 20 74 6f 20 74 68 65 |d return|s to the|
|00002650| 0d 70 72 69 6d 61 72 79 | 20 70 72 6f 6d 70 74 2e |.primary| prompt.|
|00002660| 25 0d 5c 66 6f 6f 74 6e | 6f 74 65 7b 0d 20 20 20 |%.\footn|ote{. |
|00002670| 20 20 20 20 20 41 20 70 | 72 6f 62 6c 65 6d 20 77 | A p|roblem w|
|00002680| 69 74 68 20 74 68 65 20 | 47 4e 55 20 52 65 61 64 |ith the |GNU Read|
|00002690| 6c 69 6e 65 20 70 61 63 | 6b 61 67 65 20 6d 61 79 |line pac|kage may|
|000026a0| 20 70 72 65 76 65 6e 74 | 20 74 68 69 73 2e 0d 7d | prevent| this..}|
|000026b0| 0d 54 79 70 69 6e 67 20 | 61 6e 20 69 6e 74 65 72 |.Typing |an inter|
|000026c0| 72 75 70 74 20 77 68 69 | 6c 65 20 61 20 63 6f 6d |rupt whi|le a com|
|000026d0| 6d 61 6e 64 20 69 73 20 | 65 78 65 63 75 74 69 6e |mand is |executin|
|000026e0| 67 20 72 61 69 73 65 73 | 20 74 68 65 20 7b 5c 74 |g raises| the {\t|
|000026f0| 74 0d 4b 65 79 62 6f 61 | 72 64 49 6e 74 65 72 72 |t.Keyboa|rdInterr|
|00002700| 75 70 74 7d 20 65 78 63 | 65 70 74 69 6f 6e 2c 20 |upt} exc|eption, |
|00002710| 77 68 69 63 68 20 6d 61 | 79 20 62 65 20 68 61 6e |which ma|y be han|
|00002720| 64 6c 65 64 20 62 79 20 | 61 20 7b 5c 74 74 20 74 |dled by |a {\tt t|
|00002730| 72 79 7d 0d 73 74 61 74 | 65 6d 65 6e 74 2e 0d 0d |ry}.stat|ement...|
|00002740| 5c 73 75 62 73 65 63 74 | 69 6f 6e 7b 54 68 65 20 |\subsect|ion{The |
|00002750| 4d 6f 64 75 6c 65 20 53 | 65 61 72 63 68 20 50 61 |Module S|earch Pa|
|00002760| 74 68 7d 0d 0d 57 68 65 | 6e 20 61 20 6d 6f 64 75 |th}..Whe|n a modu|
|00002770| 6c 65 20 6e 61 6d 65 64 | 20 7b 5c 74 74 20 73 70 |le named| {\tt sp|
|00002780| 61 6d 7d 20 69 73 20 69 | 6d 70 6f 72 74 65 64 2c |am} is i|mported,|
|00002790| 20 74 68 65 20 69 6e 74 | 65 72 70 72 65 74 65 72 | the int|erpreter|
|000027a0| 20 73 65 61 72 63 68 65 | 73 0d 66 6f 72 20 61 20 | searche|s.for a |
|000027b0| 66 69 6c 65 20 6e 61 6d | 65 64 20 7b 5c 74 74 20 |file nam|ed {\tt |
|000027c0| 73 70 61 6d 2e 70 79 7d | 20 69 6e 20 74 68 65 20 |spam.py}| in the |
|000027d0| 6c 69 73 74 20 6f 66 20 | 64 69 72 65 63 74 6f 72 |list of |director|
|000027e0| 69 65 73 20 73 70 65 63 | 69 66 69 65 64 20 62 79 |ies spec|ified by|
|000027f0| 0d 74 68 65 20 65 6e 76 | 69 72 6f 6e 6d 65 6e 74 |.the env|ironment|
|00002800| 20 76 61 72 69 61 62 6c | 65 20 7b 5c 74 74 20 50 | variabl|e {\tt P|
|00002810| 59 54 48 4f 4e 50 41 54 | 48 7d 2e 20 20 49 74 20 |YTHONPAT|H}. It |
|00002820| 68 61 73 20 74 68 65 20 | 73 61 6d 65 20 73 79 6e |has the |same syn|
|00002830| 74 61 78 20 61 73 0d 74 | 68 65 20 7b 5c 55 4e 49 |tax as.t|he {\UNI|
|00002840| 58 7d 20 73 68 65 6c 6c | 20 76 61 72 69 61 62 6c |X} shell| variabl|
|00002850| 65 20 7b 5c 74 74 20 50 | 41 54 48 7d 2c 20 69 2e |e {\tt P|ATH}, i.|
|00002860| 65 2e 2c 20 61 20 6c 69 | 73 74 20 6f 66 20 63 6f |e., a li|st of co|
|00002870| 6c 6f 6e 2d 73 65 70 61 | 72 61 74 65 64 0d 64 69 |lon-sepa|rated.di|
|00002880| 72 65 63 74 6f 72 79 20 | 6e 61 6d 65 73 2e 20 20 |rectory |names. |
|00002890| 57 68 65 6e 20 7b 5c 74 | 74 20 50 59 54 48 4f 4e |When {\t|t PYTHON|
|000028a0| 50 41 54 48 7d 20 69 73 | 20 6e 6f 74 20 73 65 74 |PATH} is| not set|
|000028b0| 2c 20 6f 72 20 77 68 65 | 6e 20 74 68 65 20 66 69 |, or whe|n the fi|
|000028c0| 6c 65 0d 69 73 20 6e 6f | 74 20 66 6f 75 6e 64 20 |le.is no|t found |
|000028d0| 74 68 65 72 65 2c 20 74 | 68 65 20 73 65 61 72 63 |there, t|he searc|
|000028e0| 68 20 63 6f 6e 74 69 6e | 75 65 73 20 69 6e 20 61 |h contin|ues in a|
|000028f0| 6e 20 69 6e 73 74 61 6c | 6c 61 74 69 6f 6e 2d 64 |n instal|lation-d|
|00002900| 65 70 65 6e 64 65 6e 74 | 0d 64 65 66 61 75 6c 74 |ependent|.default|
|00002910| 20 70 61 74 68 2c 20 75 | 73 75 61 6c 6c 79 20 7b | path, u|sually {|
|00002920| 5c 74 74 20 2e 3a 2f 75 | 73 72 2f 6c 6f 63 61 6c |\tt .:/u|sr/local|
|00002930| 2f 6c 69 62 2f 70 79 74 | 68 6f 6e 7d 2e 0d 0d 41 |/lib/pyt|hon}...A|
|00002940| 63 74 75 61 6c 6c 79 2c | 20 6d 6f 64 75 6c 65 73 |ctually,| modules|
|00002950| 20 61 72 65 20 73 65 61 | 72 63 68 65 64 20 69 6e | are sea|rched in|
|00002960| 20 74 68 65 20 6c 69 73 | 74 20 6f 66 20 64 69 72 | the lis|t of dir|
|00002970| 65 63 74 6f 72 69 65 73 | 20 67 69 76 65 6e 20 62 |ectories| given b|
|00002980| 79 20 74 68 65 0d 76 61 | 72 69 61 62 6c 65 20 7b |y the.va|riable {|
|00002990| 5c 74 74 20 73 79 73 2e | 70 61 74 68 7d 20 77 68 |\tt sys.|path} wh|
|000029a0| 69 63 68 20 69 73 20 69 | 6e 69 74 69 61 6c 69 7a |ich is i|nitializ|
|000029b0| 65 64 20 66 72 6f 6d 20 | 7b 5c 74 74 20 50 59 54 |ed from |{\tt PYT|
|000029c0| 48 4f 4e 50 41 54 48 7d | 20 61 6e 64 0d 74 68 65 |HONPATH}| and.the|
|000029d0| 20 69 6e 73 74 61 6c 6c | 61 74 69 6f 6e 2d 64 65 | install|ation-de|
|000029e0| 70 65 6e 64 65 6e 74 20 | 64 65 66 61 75 6c 74 2e |pendent |default.|
|000029f0| 20 20 54 68 69 73 20 61 | 6c 6c 6f 77 73 20 50 79 | This a|llows Py|
|00002a00| 74 68 6f 6e 20 70 72 6f | 67 72 61 6d 73 20 74 68 |thon pro|grams th|
|00002a10| 61 74 0d 6b 6e 6f 77 20 | 77 68 61 74 20 74 68 65 |at.know |what the|
|00002a20| 79 27 72 65 20 64 6f 69 | 6e 67 20 74 6f 20 6d 6f |y're doi|ng to mo|
|00002a30| 64 69 66 79 20 6f 72 20 | 72 65 70 6c 61 63 65 20 |dify or |replace |
|00002a40| 74 68 65 20 6d 6f 64 75 | 6c 65 20 73 65 61 72 63 |the modu|le searc|
|00002a50| 68 20 70 61 74 68 2e 0d | 53 65 65 20 74 68 65 20 |h path..|See the |
|00002a60| 73 65 63 74 69 6f 6e 20 | 6f 6e 20 53 74 61 6e 64 |section |on Stand|
|00002a70| 61 72 64 20 4d 6f 64 75 | 6c 65 73 20 6c 61 74 65 |ard Modu|les late|
|00002a80| 72 2e 0d 0d 5c 73 75 62 | 73 65 63 74 69 6f 6e 7b |r...\sub|section{|
|00002a90| 60 60 43 6f 6d 70 69 6c | 65 64 27 27 20 50 79 74 |``Compil|ed'' Pyt|
|00002aa0| 68 6f 6e 20 66 69 6c 65 | 73 7d 0d 0d 41 73 20 61 |hon file|s}..As a|
|00002ab0| 6e 20 69 6d 70 6f 72 74 | 61 6e 74 20 73 70 65 65 |n import|ant spee|
|00002ac0| 64 2d 75 70 20 6f 66 20 | 74 68 65 20 73 74 61 72 |d-up of |the star|
|00002ad0| 74 2d 75 70 20 74 69 6d | 65 20 66 6f 72 20 73 68 |t-up tim|e for sh|
|00002ae0| 6f 72 74 20 70 72 6f 67 | 72 61 6d 73 20 74 68 61 |ort prog|rams tha|
|00002af0| 74 0d 75 73 65 20 61 20 | 6c 6f 74 20 6f 66 20 73 |t.use a |lot of s|
|00002b00| 74 61 6e 64 61 72 64 20 | 6d 6f 64 75 6c 65 73 2c |tandard |modules,|
|00002b10| 20 69 66 20 61 20 66 69 | 6c 65 20 63 61 6c 6c 65 | if a fi|le calle|
|00002b20| 64 20 7b 5c 74 74 20 73 | 70 61 6d 2e 70 79 63 7d |d {\tt s|pam.pyc}|
|00002b30| 20 65 78 69 73 74 73 0d | 69 6e 20 74 68 65 20 64 | exists.|in the d|
|00002b40| 69 72 65 63 74 6f 72 79 | 20 77 68 65 72 65 20 7b |irectory| where {|
|00002b50| 5c 74 74 20 73 70 61 6d | 2e 70 79 7d 20 69 73 20 |\tt spam|.py} is |
|00002b60| 66 6f 75 6e 64 2c 20 74 | 68 69 73 20 69 73 20 61 |found, t|his is a|
|00002b70| 73 73 75 6d 65 64 20 74 | 6f 0d 63 6f 6e 74 61 69 |ssumed t|o.contai|
|00002b80| 6e 20 61 6e 20 61 6c 72 | 65 61 64 79 2d 60 60 63 |n an alr|eady-``c|
|00002b90| 6f 6d 70 69 6c 65 64 27 | 27 20 76 65 72 73 69 6f |ompiled'|' versio|
|00002ba0| 6e 20 6f 66 20 74 68 65 | 20 6d 6f 64 75 6c 65 20 |n of the| module |
|00002bb0| 7b 5c 74 74 20 73 70 61 | 6d 7d 2e 20 20 54 68 65 |{\tt spa|m}. The|
|00002bc0| 0d 6d 6f 64 69 66 69 63 | 61 74 69 6f 6e 20 74 69 |.modific|ation ti|
|00002bd0| 6d 65 20 6f 66 20 74 68 | 65 20 76 65 72 73 69 6f |me of th|e versio|
|00002be0| 6e 20 6f 66 20 7b 5c 74 | 74 20 73 70 61 6d 2e 70 |n of {\t|t spam.p|
|00002bf0| 79 7d 20 75 73 65 64 20 | 74 6f 20 63 72 65 61 74 |y} used |to creat|
|00002c00| 65 20 7b 5c 74 74 0d 73 | 70 61 6d 2e 70 79 63 7d |e {\tt.s|pam.pyc}|
|00002c10| 20 69 73 20 72 65 63 6f | 72 64 65 64 20 69 6e 20 | is reco|rded in |
|00002c20| 7b 5c 74 74 20 73 70 61 | 6d 2e 70 79 63 7d 2c 20 |{\tt spa|m.pyc}, |
|00002c30| 61 6e 64 20 74 68 65 20 | 66 69 6c 65 20 69 73 20 |and the |file is |
|00002c40| 69 67 6e 6f 72 65 64 20 | 69 66 0d 74 68 65 73 65 |ignored |if.these|
|00002c50| 20 64 6f 6e 27 74 20 6d | 61 74 63 68 2e 0d 0d 57 | don't m|atch...W|
|00002c60| 68 65 6e 65 76 65 72 20 | 7b 5c 74 74 20 73 70 61 |henever |{\tt spa|
|00002c70| 6d 2e 70 79 7d 20 69 73 | 20 73 75 63 63 65 73 73 |m.py} is| success|
|00002c80| 66 75 6c 6c 79 20 63 6f | 6d 70 69 6c 65 64 2c 20 |fully co|mpiled, |
|00002c90| 61 6e 20 61 74 74 65 6d | 70 74 20 69 73 20 6d 61 |an attem|pt is ma|
|00002ca0| 64 65 20 74 6f 0d 77 72 | 69 74 65 20 74 68 65 20 |de to.wr|ite the |
|00002cb0| 63 6f 6d 70 69 6c 65 64 | 20 76 65 72 73 69 6f 6e |compiled| version|
|00002cc0| 20 74 6f 20 7b 5c 74 74 | 20 73 70 61 6d 2e 70 79 | to {\tt| spam.py|
|00002cd0| 63 7d 2e 20 20 49 74 20 | 69 73 20 6e 6f 74 20 61 |c}. It |is not a|
|00002ce0| 6e 20 65 72 72 6f 72 20 | 69 66 0d 74 68 69 73 20 |n error |if.this |
|00002cf0| 61 74 74 65 6d 70 74 20 | 66 61 69 6c 73 3b 20 69 |attempt |fails; i|
|00002d00| 66 20 66 6f 72 20 61 6e | 79 20 72 65 61 73 6f 6e |f for an|y reason|
|00002d10| 20 74 68 65 20 66 69 6c | 65 20 69 73 20 6e 6f 74 | the fil|e is not|
|00002d20| 20 77 72 69 74 74 65 6e | 0d 63 6f 6d 70 6c 65 74 | written|.complet|
|00002d30| 65 6c 79 2c 20 74 68 65 | 20 72 65 73 75 6c 74 69 |ely, the| resulti|
|00002d40| 6e 67 20 7b 5c 74 74 20 | 73 70 61 6d 2e 70 79 63 |ng {\tt |spam.pyc|
|00002d50| 7d 20 66 69 6c 65 20 77 | 69 6c 6c 20 62 65 20 72 |} file w|ill be r|
|00002d60| 65 63 6f 67 6e 69 7a 65 | 64 20 61 73 0d 69 6e 76 |ecognize|d as.inv|
|00002d70| 61 6c 69 64 20 61 6e 64 | 20 74 68 75 73 20 69 67 |alid and| thus ig|
|00002d80| 6e 6f 72 65 64 20 6c 61 | 74 65 72 2e 0d 0d 5c 73 |nored la|ter...\s|
|00002d90| 75 62 73 65 63 74 69 6f | 6e 7b 45 78 65 63 75 74 |ubsectio|n{Execut|
|00002da0| 61 62 6c 65 20 50 79 74 | 68 6f 6e 20 73 63 72 69 |able Pyt|hon scri|
|00002db0| 70 74 73 7d 0d 0d 4f 6e | 20 42 53 44 27 69 73 68 |pts}..On| BSD'ish|
|00002dc0| 20 7b 5c 55 4e 49 58 7d | 20 73 79 73 74 65 6d 73 | {\UNIX}| systems|
|00002dd0| 2c 20 50 79 74 68 6f 6e | 20 73 63 72 69 70 74 73 |, Python| scripts|
|00002de0| 20 63 61 6e 20 62 65 20 | 6d 61 64 65 20 64 69 72 | can be |made dir|
|00002df0| 65 63 74 6c 79 0d 65 78 | 65 63 75 74 61 62 6c 65 |ectly.ex|ecutable|
|00002e00| 2c 20 6c 69 6b 65 20 73 | 68 65 6c 6c 20 73 63 72 |, like s|hell scr|
|00002e10| 69 70 74 73 2c 20 62 79 | 20 70 75 74 74 69 6e 67 |ipts, by| putting|
|00002e20| 20 74 68 65 20 6c 69 6e | 65 0d 0d 5c 62 63 6f 64 | the lin|e..\bcod|
|00002e30| 65 5c 62 65 67 69 6e 7b | 76 65 72 62 61 74 69 6d |e\begin{|verbatim|
|00002e40| 7d 0d 23 21 20 2f 75 73 | 72 2f 6c 6f 63 61 6c 2f |}.#! /us|r/local/|
|00002e50| 62 69 6e 2f 70 79 74 68 | 6f 6e 0d 5c 65 6e 64 7b |bin/pyth|on.\end{|
|00002e60| 76 65 72 62 61 74 69 6d | 7d 5c 65 63 6f 64 65 0d |verbatim|}\ecode.|
|00002e70| 25 0d 28 61 73 73 75 6d | 69 6e 67 20 74 68 61 74 |%.(assum|ing that|
|00002e80| 27 73 20 74 68 65 20 6e | 61 6d 65 20 6f 66 20 74 |'s the n|ame of t|
|00002e90| 68 65 20 69 6e 74 65 72 | 70 72 65 74 65 72 29 20 |he inter|preter) |
|00002ea0| 61 74 20 74 68 65 20 62 | 65 67 69 6e 6e 69 6e 67 |at the b|eginning|
|00002eb0| 20 6f 66 20 74 68 65 0d | 73 63 72 69 70 74 20 61 | of the.|script a|
|00002ec0| 6e 64 20 67 69 76 69 6e | 67 20 74 68 65 20 66 69 |nd givin|g the fi|
|00002ed0| 6c 65 20 61 6e 20 65 78 | 65 63 75 74 61 62 6c 65 |le an ex|ecutable|
|00002ee0| 20 6d 6f 64 65 2e 20 20 | 54 68 65 20 7b 5c 74 74 | mode. |The {\tt|
|00002ef0| 20 5c 23 21 7d 20 6d 75 | 73 74 20 62 65 0d 74 68 | \#!} mu|st be.th|
|00002f00| 65 20 66 69 72 73 74 20 | 74 77 6f 20 63 68 61 72 |e first |two char|
|00002f10| 61 63 74 65 72 73 20 6f | 66 20 74 68 65 20 66 69 |acters o|f the fi|
|00002f20| 6c 65 2e 0d 0d 5c 73 75 | 62 73 65 63 74 69 6f 6e |le...\su|bsection|
|00002f30| 7b 54 68 65 20 49 6e 74 | 65 72 61 63 74 69 76 65 |{The Int|eractive|
|00002f40| 20 53 74 61 72 74 75 70 | 20 46 69 6c 65 7d 0d 0d | Startup| File}..|
|00002f50| 57 68 65 6e 20 79 6f 75 | 20 75 73 65 20 50 79 74 |When you| use Pyt|
|00002f60| 68 6f 6e 20 69 6e 74 65 | 72 61 63 74 69 76 65 6c |hon inte|ractivel|
|00002f70| 79 2c 20 69 74 20 69 73 | 20 66 72 65 71 75 65 6e |y, it is| frequen|
|00002f80| 74 6c 79 20 68 61 6e 64 | 79 20 74 6f 20 68 61 76 |tly hand|y to hav|
|00002f90| 65 20 73 6f 6d 65 0d 73 | 74 61 6e 64 61 72 64 20 |e some.s|tandard |
|00002fa0| 63 6f 6d 6d 61 6e 64 73 | 20 65 78 65 63 75 74 65 |commands| execute|
|00002fb0| 64 20 65 76 65 72 79 20 | 74 69 6d 65 20 74 68 65 |d every |time the|
|00002fc0| 20 69 6e 74 65 72 70 72 | 65 74 65 72 20 69 73 20 | interpr|eter is |
|00002fd0| 73 74 61 72 74 65 64 2e | 20 20 59 6f 75 0d 63 61 |started.| You.ca|
|00002fe0| 6e 20 64 6f 20 74 68 69 | 73 20 62 79 20 73 65 74 |n do thi|s by set|
|00002ff0| 74 69 6e 67 20 61 6e 20 | 65 6e 76 69 72 6f 6e 6d |ting an |environm|
|00003000| 65 6e 74 20 76 61 72 69 | 61 62 6c 65 20 6e 61 6d |ent vari|able nam|
|00003010| 65 64 20 7b 5c 74 74 0d | 50 59 54 48 4f 4e 53 54 |ed {\tt.|PYTHONST|
|00003020| 41 52 54 55 50 7d 20 74 | 6f 20 74 68 65 20 6e 61 |ARTUP} t|o the na|
|00003030| 6d 65 20 6f 66 20 61 20 | 66 69 6c 65 20 63 6f 6e |me of a |file con|
|00003040| 74 61 69 6e 69 6e 67 20 | 79 6f 75 72 20 73 74 61 |taining |your sta|
|00003050| 72 74 2d 75 70 0d 63 6f | 6d 6d 61 6e 64 73 2e 20 |rt-up.co|mmands. |
|00003060| 20 54 68 69 73 20 69 73 | 20 73 69 6d 69 6c 61 72 | This is| similar|
|00003070| 20 74 6f 20 74 68 65 20 | 7b 5c 74 74 20 2e 70 72 | to the |{\tt .pr|
|00003080| 6f 66 69 6c 65 7d 20 66 | 65 61 74 75 72 65 20 6f |ofile} f|eature o|
|00003090| 66 20 74 68 65 20 55 4e | 49 58 0d 73 68 65 6c 6c |f the UN|IX.shell|
|000030a0| 73 2e 0d 0d 54 68 69 73 | 20 66 69 6c 65 20 69 73 |s...This| file is|
|000030b0| 20 6f 6e 6c 79 20 72 65 | 61 64 20 69 6e 20 69 6e | only re|ad in in|
|000030c0| 74 65 72 61 63 74 69 76 | 65 20 73 65 73 73 69 6f |teractiv|e sessio|
|000030d0| 6e 73 2c 20 6e 6f 74 20 | 77 68 65 6e 20 50 79 74 |ns, not |when Pyt|
|000030e0| 68 6f 6e 20 72 65 61 64 | 73 0d 63 6f 6d 6d 61 6e |hon read|s.comman|
|000030f0| 64 73 20 66 72 6f 6d 20 | 61 20 73 63 72 69 70 74 |ds from |a script|
|00003100| 2c 20 61 6e 64 20 6e 6f | 74 20 77 68 65 6e 20 7b |, and no|t when {|
|00003110| 5c 74 74 20 2f 64 65 76 | 2f 74 74 79 7d 20 69 73 |\tt /dev|/tty} is|
|00003120| 20 67 69 76 65 6e 20 61 | 73 20 74 68 65 0d 65 78 | given a|s the.ex|
|00003130| 70 6c 69 63 69 74 20 73 | 6f 75 72 63 65 20 6f 66 |plicit s|ource of|
|00003140| 20 63 6f 6d 6d 61 6e 64 | 73 20 28 77 68 69 63 68 | command|s (which|
|00003150| 20 6f 74 68 65 72 77 69 | 73 65 20 62 65 68 61 76 | otherwi|se behav|
|00003160| 65 73 20 6c 69 6b 65 20 | 61 6e 0d 69 6e 74 65 72 |es like |an.inter|
|00003170| 61 63 74 69 76 65 20 73 | 65 73 73 69 6f 6e 29 2e |active s|ession).|
|00003180| 20 20 49 74 20 69 73 20 | 65 78 65 63 75 74 65 64 | It is |executed|
|00003190| 20 69 6e 20 74 68 65 20 | 73 61 6d 65 20 6e 61 6d | in the |same nam|
|000031a0| 65 20 73 70 61 63 65 20 | 77 68 65 72 65 0d 69 6e |e space |where.in|
|000031b0| 74 65 72 61 63 74 69 76 | 65 20 63 6f 6d 6d 61 6e |teractiv|e comman|
|000031c0| 64 73 20 61 72 65 20 65 | 78 65 63 75 74 65 64 2c |ds are e|xecuted,|
|000031d0| 20 73 6f 20 74 68 61 74 | 20 6f 62 6a 65 63 74 73 | so that| objects|
|000031e0| 20 74 68 61 74 20 69 74 | 20 64 65 66 69 6e 65 73 | that it| defines|
|000031f0| 20 6f 72 0d 69 6d 70 6f | 72 74 73 20 63 61 6e 20 | or.impo|rts can |
|00003200| 62 65 20 75 73 65 64 20 | 77 69 74 68 6f 75 74 20 |be used |without |
|00003210| 71 75 61 6c 69 66 69 63 | 61 74 69 6f 6e 20 69 6e |qualific|ation in|
|00003220| 20 74 68 65 20 69 6e 74 | 65 72 61 63 74 69 76 65 | the int|eractive|
|00003230| 20 73 65 73 73 69 6f 6e | 2e 0d 59 6f 75 20 63 61 | session|..You ca|
|00003240| 6e 20 61 6c 73 6f 20 63 | 68 61 6e 67 65 20 74 68 |n also c|hange th|
|00003250| 65 20 70 72 6f 6d 70 74 | 73 20 7b 5c 74 74 20 73 |e prompt|s {\tt s|
|00003260| 79 73 2e 70 73 31 7d 20 | 61 6e 64 20 7b 5c 74 74 |ys.ps1} |and {\tt|
|00003270| 20 73 79 73 2e 70 73 32 | 7d 20 69 6e 0d 74 68 69 | sys.ps2|} in.thi|
|00003280| 73 20 66 69 6c 65 2e 0d | 0d 49 66 20 79 6f 75 20 |s file..|.If you |
|00003290| 77 61 6e 74 20 74 6f 20 | 72 65 61 64 20 61 6e 20 |want to |read an |
|000032a0| 61 64 64 69 74 69 6f 6e | 61 6c 20 73 74 61 72 74 |addition|al start|
|000032b0| 2d 75 70 20 66 69 6c 65 | 20 66 72 6f 6d 20 74 68 |-up file| from th|
|000032c0| 65 20 63 75 72 72 65 6e | 74 0d 64 69 72 65 63 74 |e curren|t.direct|
|000032d0| 6f 72 79 2c 20 79 6f 75 | 20 63 61 6e 20 70 72 6f |ory, you| can pro|
|000032e0| 67 72 61 6d 20 74 68 69 | 73 20 69 6e 20 74 68 65 |gram thi|s in the|
|000032f0| 20 67 6c 6f 62 61 6c 20 | 73 74 61 72 74 2d 75 70 | global |start-up|
|00003300| 20 66 69 6c 65 2c 20 65 | 2e 67 2e 0d 5c 76 65 72 | file, e|.g..\ver|
|00003310| 62 5c 65 78 65 63 66 69 | 6c 65 28 27 2e 70 79 74 |b\execfi|le('.pyt|
|00003320| 68 6f 6e 72 63 27 29 5c | 2e 20 20 49 66 20 79 6f |honrc')\|. If yo|
|00003330| 75 20 77 61 6e 74 20 74 | 6f 20 75 73 65 20 74 68 |u want t|o use th|
|00003340| 65 20 73 74 61 72 74 75 | 70 20 66 69 6c 65 0d 69 |e startu|p file.i|
|00003350| 6e 20 61 20 73 63 72 69 | 70 74 2c 20 79 6f 75 20 |n a scri|pt, you |
|00003360| 6d 75 73 74 20 77 72 69 | 74 65 20 74 68 69 73 20 |must wri|te this |
|00003370| 65 78 70 6c 69 63 69 74 | 6c 79 20 69 6e 20 74 68 |explicit|ly in th|
|00003380| 65 20 73 63 72 69 70 74 | 2c 20 65 2e 67 2e 0d 5c |e script|, e.g..\|
|00003390| 76 65 72 62 5c 69 6d 70 | 6f 72 74 20 6f 73 3b 5c |verb\imp|ort os;\|
|000033a0| 20 5c 76 65 72 62 5c 65 | 78 65 63 66 69 6c 65 28 | \verb\e|xecfile(|
|000033b0| 6f 73 2e 65 6e 76 69 72 | 6f 6e 5b 27 50 59 54 48 |os.envir|on['PYTH|
|000033c0| 4f 4e 53 54 41 52 54 55 | 50 27 5d 29 5c 2e 0d 0d |ONSTARTU|P'])\...|
|000033d0| 5c 73 65 63 74 69 6f 6e | 7b 49 6e 74 65 72 61 63 |\section|{Interac|
|000033e0| 74 69 76 65 20 49 6e 70 | 75 74 20 45 64 69 74 69 |tive Inp|ut Editi|
|000033f0| 6e 67 20 61 6e 64 20 48 | 69 73 74 6f 72 79 20 53 |ng and H|istory S|
|00003400| 75 62 73 74 69 74 75 74 | 69 6f 6e 7d 0d 0d 53 6f |ubstitut|ion}..So|
|00003410| 6d 65 20 76 65 72 73 69 | 6f 6e 73 20 6f 66 20 74 |me versi|ons of t|
|00003420| 68 65 20 50 79 74 68 6f | 6e 20 69 6e 74 65 72 70 |he Pytho|n interp|
|00003430| 72 65 74 65 72 20 73 75 | 70 70 6f 72 74 20 65 64 |reter su|pport ed|
|00003440| 69 74 69 6e 67 20 6f 66 | 20 74 68 65 20 63 75 72 |iting of| the cur|
|00003450| 72 65 6e 74 0d 69 6e 70 | 75 74 20 6c 69 6e 65 20 |rent.inp|ut line |
|00003460| 61 6e 64 20 68 69 73 74 | 6f 72 79 20 73 75 62 73 |and hist|ory subs|
|00003470| 74 69 74 75 74 69 6f 6e | 2c 20 73 69 6d 69 6c 61 |titution|, simila|
|00003480| 72 20 74 6f 20 66 61 63 | 69 6c 69 74 69 65 73 20 |r to fac|ilities |
|00003490| 66 6f 75 6e 64 20 69 6e | 0d 74 68 65 20 4b 6f 72 |found in|.the Kor|
|000034a0| 6e 20 73 68 65 6c 6c 20 | 61 6e 64 20 74 68 65 20 |n shell |and the |
|000034b0| 47 4e 55 20 42 61 73 68 | 20 73 68 65 6c 6c 2e 20 |GNU Bash| shell. |
|000034c0| 20 54 68 69 73 20 69 73 | 20 69 6d 70 6c 65 6d 65 | This is| impleme|
|000034d0| 6e 74 65 64 20 75 73 69 | 6e 67 20 74 68 65 0d 7b |nted usi|ng the.{|
|000034e0| 5c 65 6d 20 47 4e 55 5c | 20 52 65 61 64 6c 69 6e |\em GNU\| Readlin|
|000034f0| 65 7d 20 6c 69 62 72 61 | 72 79 2c 20 77 68 69 63 |e} libra|ry, whic|
|00003500| 68 20 73 75 70 70 6f 72 | 74 73 20 45 6d 61 63 73 |h suppor|ts Emacs|
|00003510| 2d 73 74 79 6c 65 20 61 | 6e 64 20 76 69 2d 73 74 |-style a|nd vi-st|
|00003520| 79 6c 65 0d 65 64 69 74 | 69 6e 67 2e 20 20 54 68 |yle.edit|ing. Th|
|00003530| 69 73 20 6c 69 62 72 61 | 72 79 20 68 61 73 20 69 |is libra|ry has i|
|00003540| 74 73 20 6f 77 6e 20 64 | 6f 63 75 6d 65 6e 74 61 |ts own d|ocumenta|
|00003550| 74 69 6f 6e 20 77 68 69 | 63 68 20 49 20 77 6f 6e |tion whi|ch I won|
|00003560| 27 74 0d 64 75 70 6c 69 | 63 61 74 65 20 68 65 72 |'t.dupli|cate her|
|00003570| 65 3b 20 68 6f 77 65 76 | 65 72 2c 20 74 68 65 20 |e; howev|er, the |
|00003580| 62 61 73 69 63 73 20 61 | 72 65 20 65 61 73 69 6c |basics a|re easil|
|00003590| 79 20 65 78 70 6c 61 69 | 6e 65 64 2e 0d 0d 50 65 |y explai|ned...Pe|
|000035a0| 72 68 61 70 73 20 74 68 | 65 20 71 75 69 63 6b 65 |rhaps th|e quicke|
|000035b0| 73 74 20 63 68 65 63 6b | 20 74 6f 20 73 65 65 20 |st check| to see |
|000035c0| 77 68 65 74 68 65 72 20 | 63 6f 6d 6d 61 6e 64 20 |whether |command |
|000035d0| 6c 69 6e 65 20 65 64 69 | 74 69 6e 67 20 69 73 0d |line edi|ting is.|
|000035e0| 73 75 70 70 6f 72 74 65 | 64 20 69 73 20 74 79 70 |supporte|d is typ|
|000035f0| 69 6e 67 20 43 6f 6e 74 | 72 6f 6c 2d 50 20 74 6f |ing Cont|rol-P to|
|00003600| 20 74 68 65 20 66 69 72 | 73 74 20 50 79 74 68 6f | the fir|st Pytho|
|00003610| 6e 20 70 72 6f 6d 70 74 | 20 79 6f 75 20 67 65 74 |n prompt| you get|
|00003620| 2e 20 20 49 66 0d 69 74 | 20 62 65 65 70 73 2c 20 |. If.it| beeps, |
|00003630| 79 6f 75 20 68 61 76 65 | 20 63 6f 6d 6d 61 6e 64 |you have| command|
|00003640| 20 6c 69 6e 65 20 65 64 | 69 74 69 6e 67 2e 20 20 | line ed|iting. |
|00003650| 49 66 20 6e 6f 74 68 69 | 6e 67 20 61 70 70 65 61 |If nothi|ng appea|
|00003660| 72 73 20 74 6f 0d 68 61 | 70 70 65 6e 2c 20 6f 72 |rs to.ha|ppen, or|
|00003670| 20 69 66 20 5c 76 65 72 | 62 2f 5e 50 2f 20 69 73 | if \ver|b/^P/ is|
|00003680| 20 65 63 68 6f 65 64 2c | 20 79 6f 75 20 63 61 6e | echoed,| you can|
|00003690| 20 73 6b 69 70 20 74 68 | 65 20 72 65 73 74 20 6f | skip th|e rest o|
|000036a0| 66 20 74 68 69 73 0d 73 | 65 63 74 69 6f 6e 2e 0d |f this.s|ection..|
|000036b0| 0d 5c 73 75 62 73 65 63 | 74 69 6f 6e 7b 4c 69 6e |.\subsec|tion{Lin|
|000036c0| 65 20 45 64 69 74 69 6e | 67 7d 0d 0d 49 66 20 73 |e Editin|g}..If s|
|000036d0| 75 70 70 6f 72 74 65 64 | 2c 20 69 6e 70 75 74 20 |upported|, input |
|000036e0| 6c 69 6e 65 20 65 64 69 | 74 69 6e 67 20 69 73 20 |line edi|ting is |
|000036f0| 61 63 74 69 76 65 20 77 | 68 65 6e 65 76 65 72 20 |active w|henever |
|00003700| 74 68 65 20 69 6e 74 65 | 72 70 72 65 74 65 72 0d |the inte|rpreter.|
|00003710| 70 72 69 6e 74 73 20 61 | 20 70 72 69 6d 61 72 79 |prints a| primary|
|00003720| 20 6f 72 20 73 65 63 6f | 6e 64 61 72 79 20 70 72 | or seco|ndary pr|
|00003730| 6f 6d 70 74 2e 20 20 54 | 68 65 20 63 75 72 72 65 |ompt. T|he curre|
|00003740| 6e 74 20 6c 69 6e 65 20 | 63 61 6e 20 62 65 20 65 |nt line |can be e|
|00003750| 64 69 74 65 64 0d 75 73 | 69 6e 67 20 74 68 65 20 |dited.us|ing the |
|00003760| 63 6f 6e 76 65 6e 74 69 | 6f 6e 61 6c 20 45 6d 61 |conventi|onal Ema|
|00003770| 63 73 20 63 6f 6e 74 72 | 6f 6c 20 63 68 61 72 61 |cs contr|ol chara|
|00003780| 63 74 65 72 73 2e 20 20 | 54 68 65 20 6d 6f 73 74 |cters. |The most|
|00003790| 20 69 6d 70 6f 72 74 61 | 6e 74 0d 6f 66 20 74 68 | importa|nt.of th|
|000037a0| 65 73 65 20 61 72 65 3a | 20 43 2d 41 20 28 43 6f |ese are:| C-A (Co|
|000037b0| 6e 74 72 6f 6c 2d 41 29 | 20 6d 6f 76 65 73 20 74 |ntrol-A)| moves t|
|000037c0| 68 65 20 63 75 72 73 6f | 72 20 74 6f 20 74 68 65 |he curso|r to the|
|000037d0| 20 62 65 67 69 6e 6e 69 | 6e 67 20 6f 66 20 74 68 | beginni|ng of th|
|000037e0| 65 0d 6c 69 6e 65 2c 20 | 43 2d 45 20 74 6f 20 74 |e.line, |C-E to t|
|000037f0| 68 65 20 65 6e 64 2c 20 | 43 2d 42 20 6d 6f 76 65 |he end, |C-B move|
|00003800| 73 20 69 74 20 6f 6e 65 | 20 70 6f 73 69 74 69 6f |s it one| positio|
|00003810| 6e 20 74 6f 20 74 68 65 | 20 6c 65 66 74 2c 20 43 |n to the| left, C|
|00003820| 2d 46 20 74 6f 0d 74 68 | 65 20 72 69 67 68 74 2e |-F to.th|e right.|
|00003830| 20 20 42 61 63 6b 73 70 | 61 63 65 20 65 72 61 73 | Backsp|ace eras|
|00003840| 65 73 20 74 68 65 20 63 | 68 61 72 61 63 74 65 72 |es the c|haracter|
|00003850| 20 74 6f 20 74 68 65 20 | 6c 65 66 74 20 6f 66 20 | to the |left of |
|00003860| 74 68 65 20 63 75 72 73 | 6f 72 2c 0d 43 2d 44 20 |the curs|or,.C-D |
|00003870| 74 68 65 20 63 68 61 72 | 61 63 74 65 72 20 74 6f |the char|acter to|
|00003880| 20 69 74 73 20 72 69 67 | 68 74 2e 20 20 43 2d 4b | its rig|ht. C-K|
|00003890| 20 6b 69 6c 6c 73 20 28 | 65 72 61 73 65 73 29 20 | kills (|erases) |
|000038a0| 74 68 65 20 72 65 73 74 | 20 6f 66 20 74 68 65 0d |the rest| of the.|
|000038b0| 6c 69 6e 65 20 74 6f 20 | 74 68 65 20 72 69 67 68 |line to |the righ|
|000038c0| 74 20 6f 66 20 74 68 65 | 20 63 75 72 73 6f 72 2c |t of the| cursor,|
|000038d0| 20 43 2d 59 20 79 61 6e | 6b 73 20 62 61 63 6b 20 | C-Y yan|ks back |
|000038e0| 74 68 65 20 6c 61 73 74 | 20 6b 69 6c 6c 65 64 0d |the last| killed.|
|000038f0| 73 74 72 69 6e 67 2e 20 | 20 43 2d 75 6e 64 65 72 |string. | C-under|
|00003900| 73 63 6f 72 65 20 75 6e | 64 6f 65 73 20 74 68 65 |score un|does the|
|00003910| 20 6c 61 73 74 20 63 68 | 61 6e 67 65 20 79 6f 75 | last ch|ange you|
|00003920| 20 6d 61 64 65 3b 20 69 | 74 20 63 61 6e 20 62 65 | made; i|t can be|
|00003930| 0d 72 65 70 65 61 74 65 | 64 20 66 6f 72 20 63 75 |.repeate|d for cu|
|00003940| 6d 75 6c 61 74 69 76 65 | 20 65 66 66 65 63 74 2e |mulative| effect.|
|00003950| 0d 0d 5c 73 75 62 73 65 | 63 74 69 6f 6e 7b 48 69 |..\subse|ction{Hi|
|00003960| 73 74 6f 72 79 20 53 75 | 62 73 74 69 74 75 74 69 |story Su|bstituti|
|00003970| 6f 6e 7d 0d 0d 48 69 73 | 74 6f 72 79 20 73 75 62 |on}..His|tory sub|
|00003980| 73 74 69 74 75 74 69 6f | 6e 20 77 6f 72 6b 73 20 |stitutio|n works |
|00003990| 61 73 20 66 6f 6c 6c 6f | 77 73 2e 20 20 41 6c 6c |as follo|ws. All|
|000039a0| 20 6e 6f 6e 2d 65 6d 70 | 74 79 20 69 6e 70 75 74 | non-emp|ty input|
|000039b0| 20 6c 69 6e 65 73 0d 69 | 73 73 75 65 64 20 61 72 | lines.i|ssued ar|
|000039c0| 65 20 73 61 76 65 64 20 | 69 6e 20 61 20 68 69 73 |e saved |in a his|
|000039d0| 74 6f 72 79 20 62 75 66 | 66 65 72 2c 20 61 6e 64 |tory buf|fer, and|
|000039e0| 20 77 68 65 6e 20 61 20 | 6e 65 77 20 70 72 6f 6d | when a |new prom|
|000039f0| 70 74 20 69 73 20 67 69 | 76 65 6e 0d 79 6f 75 20 |pt is gi|ven.you |
|00003a00| 61 72 65 20 70 6f 73 69 | 74 69 6f 6e 65 64 20 6f |are posi|tioned o|
|00003a10| 6e 20 61 20 6e 65 77 20 | 6c 69 6e 65 20 61 74 20 |n a new |line at |
|00003a20| 74 68 65 20 62 6f 74 74 | 6f 6d 20 6f 66 20 74 68 |the bott|om of th|
|00003a30| 69 73 20 62 75 66 66 65 | 72 2e 20 20 43 2d 50 0d |is buffe|r. C-P.|
|00003a40| 6d 6f 76 65 73 20 6f 6e | 65 20 6c 69 6e 65 20 75 |moves on|e line u|
|00003a50| 70 20 28 62 61 63 6b 29 | 20 69 6e 20 74 68 65 20 |p (back)| in the |
|00003a60| 68 69 73 74 6f 72 79 20 | 62 75 66 66 65 72 2c 20 |history |buffer, |
|00003a70| 43 2d 4e 20 6d 6f 76 65 | 73 20 6f 6e 65 20 64 6f |C-N move|s one do|
|00003a80| 77 6e 2e 0d 41 6e 79 20 | 6c 69 6e 65 20 69 6e 20 |wn..Any |line in |
|00003a90| 74 68 65 20 68 69 73 74 | 6f 72 79 20 62 75 66 66 |the hist|ory buff|
|00003aa0| 65 72 20 63 61 6e 20 62 | 65 20 65 64 69 74 65 64 |er can b|e edited|
|00003ab0| 3b 20 61 6e 20 61 73 74 | 65 72 69 73 6b 20 61 70 |; an ast|erisk ap|
|00003ac0| 70 65 61 72 73 20 69 6e | 0d 66 72 6f 6e 74 20 6f |pears in|.front o|
|00003ad0| 66 20 74 68 65 20 70 72 | 6f 6d 70 74 20 74 6f 20 |f the pr|ompt to |
|00003ae0| 6d 61 72 6b 20 61 20 6c | 69 6e 65 20 61 73 20 6d |mark a l|ine as m|
|00003af0| 6f 64 69 66 69 65 64 2e | 20 20 50 72 65 73 73 69 |odified.| Pressi|
|00003b00| 6e 67 20 74 68 65 20 52 | 65 74 75 72 6e 0d 6b 65 |ng the R|eturn.ke|
|00003b10| 79 20 70 61 73 73 65 73 | 20 74 68 65 20 63 75 72 |y passes| the cur|
|00003b20| 72 65 6e 74 20 6c 69 6e | 65 20 74 6f 20 74 68 65 |rent lin|e to the|
|00003b30| 20 69 6e 74 65 72 70 72 | 65 74 65 72 2e 20 20 43 | interpr|eter. C|
|00003b40| 2d 52 20 73 74 61 72 74 | 73 20 61 6e 0d 69 6e 63 |-R start|s an.inc|
|00003b50| 72 65 6d 65 6e 74 61 6c | 20 72 65 76 65 72 73 65 |remental| reverse|
|00003b60| 20 73 65 61 72 63 68 3b | 20 43 2d 53 20 73 74 61 | search;| C-S sta|
|00003b70| 72 74 73 20 61 20 66 6f | 72 77 61 72 64 20 73 65 |rts a fo|rward se|
|00003b80| 61 72 63 68 2e 0d 0d 5c | 73 75 62 73 65 63 74 69 |arch...\|subsecti|
|00003b90| 6f 6e 7b 4b 65 79 20 42 | 69 6e 64 69 6e 67 73 7d |on{Key B|indings}|
|00003ba0| 0d 0d 54 68 65 20 6b 65 | 79 20 62 69 6e 64 69 6e |..The ke|y bindin|
|00003bb0| 67 73 20 61 6e 64 20 73 | 6f 6d 65 20 6f 74 68 65 |gs and s|ome othe|
|00003bc0| 72 20 70 61 72 61 6d 65 | 74 65 72 73 20 6f 66 20 |r parame|ters of |
|00003bd0| 74 68 65 20 52 65 61 64 | 6c 69 6e 65 20 6c 69 62 |the Read|line lib|
|00003be0| 72 61 72 79 20 63 61 6e | 0d 62 65 20 63 75 73 74 |rary can|.be cust|
|00003bf0| 6f 6d 69 7a 65 64 20 62 | 79 20 70 6c 61 63 69 6e |omized b|y placin|
|00003c00| 67 20 63 6f 6d 6d 61 6e | 64 73 20 69 6e 20 61 6e |g comman|ds in an|
|00003c10| 20 69 6e 69 74 69 61 6c | 69 7a 61 74 69 6f 6e 20 | initial|ization |
|00003c20| 66 69 6c 65 20 63 61 6c | 6c 65 64 0d 7b 5c 74 74 |file cal|led.{\tt|
|00003c30| 20 5c 24 48 4f 4d 45 2f | 2e 69 6e 70 75 74 72 63 | \$HOME/|.inputrc|
|00003c40| 7d 2e 20 20 4b 65 79 20 | 62 69 6e 64 69 6e 67 73 |}. Key |bindings|
|00003c50| 20 68 61 76 65 20 74 68 | 65 20 66 6f 72 6d 0d 0d | have th|e form..|
|00003c60| 5c 62 63 6f 64 65 5c 62 | 65 67 69 6e 7b 76 65 72 |\bcode\b|egin{ver|
|00003c70| 62 61 74 69 6d 7d 0d 6b | 65 79 2d 6e 61 6d 65 3a |batim}.k|ey-name:|
|00003c80| 20 66 75 6e 63 74 69 6f | 6e 2d 6e 61 6d 65 0d 5c | functio|n-name.\|
|00003c90| 65 6e 64 7b 76 65 72 62 | 61 74 69 6d 7d 5c 65 63 |end{verb|atim}\ec|
|00003ca0| 6f 64 65 0d 25 0d 6f 72 | 0d 0d 5c 62 63 6f 64 65 |ode.%.or|..\bcode|
|00003cb0| 5c 62 65 67 69 6e 7b 76 | 65 72 62 61 74 69 6d 7d |\begin{v|erbatim}|
|00003cc0| 0d 22 73 74 72 69 6e 67 | 22 3a 20 66 75 6e 63 74 |."string|": funct|
|00003cd0| 69 6f 6e 2d 6e 61 6d 65 | 0d 5c 65 6e 64 7b 76 65 |ion-name|.\end{ve|
|00003ce0| 72 62 61 74 69 6d 7d 5c | 65 63 6f 64 65 0d 25 0d |rbatim}\|ecode.%.|
|00003cf0| 61 6e 64 20 6f 70 74 69 | 6f 6e 73 20 63 61 6e 20 |and opti|ons can |
|00003d00| 62 65 20 73 65 74 20 77 | 69 74 68 0d 0d 5c 62 63 |be set w|ith..\bc|
|00003d10| 6f 64 65 5c 62 65 67 69 | 6e 7b 76 65 72 62 61 74 |ode\begi|n{verbat|
|00003d20| 69 6d 7d 0d 73 65 74 20 | 6f 70 74 69 6f 6e 2d 6e |im}.set |option-n|
|00003d30| 61 6d 65 20 76 61 6c 75 | 65 0d 5c 65 6e 64 7b 76 |ame valu|e.\end{v|
|00003d40| 65 72 62 61 74 69 6d 7d | 5c 65 63 6f 64 65 0d 25 |erbatim}|\ecode.%|
|00003d50| 0d 46 6f 72 20 65 78 61 | 6d 70 6c 65 3a 0d 0d 5c |.For exa|mple:..\|
|00003d60| 62 63 6f 64 65 5c 62 65 | 67 69 6e 7b 76 65 72 62 |bcode\be|gin{verb|
|00003d70| 61 74 69 6d 7d 0d 23 20 | 49 20 70 72 65 66 65 72 |atim}.# |I prefer|
|00003d80| 20 76 69 2d 73 74 79 6c | 65 20 65 64 69 74 69 6e | vi-styl|e editin|
|00003d90| 67 3a 0d 73 65 74 20 65 | 64 69 74 69 6e 67 2d 6d |g:.set e|diting-m|
|00003da0| 6f 64 65 20 76 69 0d 23 | 20 45 64 69 74 20 75 73 |ode vi.#| Edit us|
|00003db0| 69 6e 67 20 61 20 73 69 | 6e 67 6c 65 20 6c 69 6e |ing a si|ngle lin|
|00003dc0| 65 3a 0d 73 65 74 20 68 | 6f 72 69 7a 6f 6e 74 61 |e:.set h|orizonta|
|00003dd0| 6c 2d 73 63 72 6f 6c 6c | 2d 6d 6f 64 65 20 4f 6e |l-scroll|-mode On|
|00003de0| 0d 23 20 52 65 62 69 6e | 64 20 73 6f 6d 65 20 6b |.# Rebin|d some k|
|00003df0| 65 79 73 3a 0d 4d 65 74 | 61 2d 68 3a 20 62 61 63 |eys:.Met|a-h: bac|
|00003e00| 6b 77 61 72 64 2d 6b 69 | 6c 6c 2d 77 6f 72 64 0d |kward-ki|ll-word.|
|00003e10| 22 5c 43 2d 75 22 3a 20 | 75 6e 69 76 65 72 73 61 |"\C-u": |universa|
|00003e20| 6c 2d 61 72 67 75 6d 65 | 6e 74 0d 22 5c 43 2d 78 |l-argume|nt."\C-x|
|00003e30| 5c 43 2d 72 22 3a 20 72 | 65 2d 72 65 61 64 2d 69 |\C-r": r|e-read-i|
|00003e40| 6e 69 74 2d 66 69 6c 65 | 0d 5c 65 6e 64 7b 76 65 |nit-file|.\end{ve|
|00003e50| 72 62 61 74 69 6d 7d 5c | 65 63 6f 64 65 0d 25 0d |rbatim}\|ecode.%.|
|00003e60| 4e 6f 74 65 20 74 68 61 | 74 20 74 68 65 20 64 65 |Note tha|t the de|
|00003e70| 66 61 75 6c 74 20 62 69 | 6e 64 69 6e 67 20 66 6f |fault bi|nding fo|
|00003e80| 72 20 54 41 42 20 69 6e | 20 50 79 74 68 6f 6e 20 |r TAB in| Python |
|00003e90| 69 73 20 74 6f 20 69 6e | 73 65 72 74 20 61 20 54 |is to in|sert a T|
|00003ea0| 41 42 0d 69 6e 73 74 65 | 61 64 20 6f 66 20 52 65 |AB.inste|ad of Re|
|00003eb0| 61 64 6c 69 6e 65 27 73 | 20 64 65 66 61 75 6c 74 |adline's| default|
|00003ec0| 20 66 69 6c 65 6e 61 6d | 65 20 63 6f 6d 70 6c 65 | filenam|e comple|
|00003ed0| 74 69 6f 6e 20 66 75 6e | 63 74 69 6f 6e 2e 20 20 |tion fun|ction. |
|00003ee0| 49 66 20 79 6f 75 0d 69 | 6e 73 69 73 74 2c 20 79 |If you.i|nsist, y|
|00003ef0| 6f 75 20 63 61 6e 20 6f | 76 65 72 72 69 64 65 20 |ou can o|verride |
|00003f00| 74 68 69 73 20 62 79 20 | 70 75 74 74 69 6e 67 0d |this by |putting.|
|00003f10| 0d 5c 62 63 6f 64 65 5c | 62 65 67 69 6e 7b 76 65 |.\bcode\|begin{ve|
|00003f20| 72 62 61 74 69 6d 7d 0d | 54 41 42 3a 20 63 6f 6d |rbatim}.|TAB: com|
|00003f30| 70 6c 65 74 65 0d 5c 65 | 6e 64 7b 76 65 72 62 61 |plete.\e|nd{verba|
|00003f40| 74 69 6d 7d 5c 65 63 6f | 64 65 0d 25 0d 69 6e 20 |tim}\eco|de.%.in |
|00003f50| 79 6f 75 72 20 7b 5c 74 | 74 20 5c 24 48 4f 4d 45 |your {\t|t \$HOME|
|00003f60| 2f 2e 69 6e 70 75 74 72 | 63 7d 2e 20 20 28 4f 66 |/.inputr|c}. (Of|
|00003f70| 20 63 6f 75 72 73 65 2c | 20 74 68 69 73 20 6d 61 | course,| this ma|
|00003f80| 6b 65 73 20 69 74 20 68 | 61 72 64 20 74 6f 20 74 |kes it h|ard to t|
|00003f90| 79 70 65 0d 69 6e 64 65 | 6e 74 65 64 20 63 6f 6e |ype.inde|nted con|
|00003fa0| 74 69 6e 75 61 74 69 6f | 6e 20 6c 69 6e 65 73 2e |tinuatio|n lines.|
|00003fb0| 2e 2e 29 0d 0d 5c 73 75 | 62 73 65 63 74 69 6f 6e |..)..\su|bsection|
|00003fc0| 7b 43 6f 6d 6d 65 6e 74 | 61 72 79 7d 0d 0d 54 68 |{Comment|ary}..Th|
|00003fd0| 69 73 20 66 61 63 69 6c | 69 74 79 20 69 73 20 61 |is facil|ity is a|
|00003fe0| 6e 20 65 6e 6f 72 6d 6f | 75 73 20 73 74 65 70 20 |n enormo|us step |
|00003ff0| 66 6f 72 77 61 72 64 20 | 63 6f 6d 70 61 72 65 64 |forward |compared|
|00004000| 20 74 6f 20 70 72 65 76 | 69 6f 75 73 0d 76 65 72 | to prev|ious.ver|
|00004010| 73 69 6f 6e 73 20 6f 66 | 20 74 68 65 20 69 6e 74 |sions of| the int|
|00004020| 65 72 70 72 65 74 65 72 | 3b 20 68 6f 77 65 76 65 |erpreter|; howeve|
|00004030| 72 2c 20 73 6f 6d 65 20 | 77 69 73 68 65 73 20 61 |r, some |wishes a|
|00004040| 72 65 20 6c 65 66 74 3a | 20 49 74 20 77 6f 75 6c |re left:| It woul|
|00004050| 64 0d 62 65 20 6e 69 63 | 65 20 69 66 20 74 68 65 |d.be nic|e if the|
|00004060| 20 70 72 6f 70 65 72 20 | 69 6e 64 65 6e 74 61 74 | proper |indentat|
|00004070| 69 6f 6e 20 77 65 72 65 | 20 73 75 67 67 65 73 74 |ion were| suggest|
|00004080| 65 64 20 6f 6e 20 63 6f | 6e 74 69 6e 75 61 74 69 |ed on co|ntinuati|
|00004090| 6f 6e 20 6c 69 6e 65 73 | 0d 28 74 68 65 20 70 61 |on lines|.(the pa|
|000040a0| 72 73 65 72 20 6b 6e 6f | 77 73 20 69 66 20 61 6e |rser kno|ws if an|
|000040b0| 20 69 6e 64 65 6e 74 20 | 74 6f 6b 65 6e 20 69 73 | indent |token is|
|000040c0| 20 72 65 71 75 69 72 65 | 64 20 6e 65 78 74 29 2e | require|d next).|
|000040d0| 20 20 54 68 65 0d 63 6f | 6d 70 6c 65 74 69 6f 6e | The.co|mpletion|
|000040e0| 20 6d 65 63 68 61 6e 69 | 73 6d 20 6d 69 67 68 74 | mechani|sm might|
|000040f0| 20 75 73 65 20 74 68 65 | 20 69 6e 74 65 72 70 72 | use the| interpr|
|00004100| 65 74 65 72 27 73 20 73 | 79 6d 62 6f 6c 20 74 61 |eter's s|ymbol ta|
|00004110| 62 6c 65 2e 20 20 41 0d | 63 6f 6d 6d 61 6e 64 20 |ble. A.|command |
|00004120| 74 6f 20 63 68 65 63 6b | 20 28 6f 72 20 65 76 65 |to check| (or eve|
|00004130| 6e 20 73 75 67 67 65 73 | 74 29 20 6d 61 74 63 68 |n sugges|t) match|
|00004140| 69 6e 67 20 70 61 72 65 | 6e 74 68 65 73 65 73 2c |ing pare|ntheses,|
|00004150| 20 71 75 6f 74 65 73 20 | 65 74 63 2e 0d 77 6f 75 | quotes |etc..wou|
|00004160| 6c 64 20 61 6c 73 6f 20 | 62 65 20 75 73 65 66 75 |ld also |be usefu|
|00004170| 6c 2e 0d 0d 0d 5c 63 68 | 61 70 74 65 72 7b 41 6e |l....\ch|apter{An|
|00004180| 20 49 6e 66 6f 72 6d 61 | 6c 20 49 6e 74 72 6f 64 | Informa|l Introd|
|00004190| 75 63 74 69 6f 6e 20 74 | 6f 20 50 79 74 68 6f 6e |uction t|o Python|
|000041a0| 7d 0d 0d 49 6e 20 74 68 | 65 20 66 6f 6c 6c 6f 77 |}..In th|e follow|
|000041b0| 69 6e 67 20 65 78 61 6d | 70 6c 65 73 2c 20 69 6e |ing exam|ples, in|
|000041c0| 70 75 74 20 61 6e 64 20 | 6f 75 74 70 75 74 20 61 |put and |output a|
|000041d0| 72 65 20 64 69 73 74 69 | 6e 67 75 69 73 68 65 64 |re disti|nguished|
|000041e0| 20 62 79 20 74 68 65 0d | 70 72 65 73 65 6e 63 65 | by the.|presence|
|000041f0| 20 6f 72 20 61 62 73 65 | 6e 63 65 20 6f 66 20 70 | or abse|nce of p|
|00004200| 72 6f 6d 70 74 73 20 28 | 7b 5c 74 74 20 3e 3e 3e |rompts (|{\tt >>>|
|00004210| 7d 20 61 6e 64 20 7b 5c | 74 74 20 2e 2e 2e 7d 29 |} and {\|tt ...})|
|00004220| 3a 20 74 6f 20 72 65 70 | 65 61 74 0d 74 68 65 20 |: to rep|eat.the |
|00004230| 65 78 61 6d 70 6c 65 2c | 20 79 6f 75 20 6d 75 73 |example,| you mus|
|00004240| 74 20 74 79 70 65 20 65 | 76 65 72 79 74 68 69 6e |t type e|verythin|
|00004250| 67 20 61 66 74 65 72 20 | 74 68 65 20 70 72 6f 6d |g after |the prom|
|00004260| 70 74 2c 20 77 68 65 6e | 20 74 68 65 0d 70 72 6f |pt, when| the.pro|
|00004270| 6d 70 74 20 61 70 70 65 | 61 72 73 3b 20 6c 69 6e |mpt appe|ars; lin|
|00004280| 65 73 20 74 68 61 74 20 | 64 6f 20 6e 6f 74 20 62 |es that |do not b|
|00004290| 65 67 69 6e 20 77 69 74 | 68 20 61 20 70 72 6f 6d |egin wit|h a prom|
|000042a0| 70 74 20 61 72 65 20 6f | 75 74 70 75 74 20 66 72 |pt are o|utput fr|
|000042b0| 6f 6d 0d 74 68 65 20 69 | 6e 74 65 72 70 72 65 74 |om.the i|nterpret|
|000042c0| 65 72 2e 25 0d 5c 66 6f | 6f 74 6e 6f 74 65 7b 0d |er.%.\fo|otnote{.|
|000042d0| 20 20 20 20 20 20 20 20 | 49 27 64 20 70 72 65 66 | |I'd pref|
|000042e0| 65 72 20 74 6f 20 75 73 | 65 20 64 69 66 66 65 72 |er to us|e differ|
|000042f0| 65 6e 74 20 66 6f 6e 74 | 73 20 74 6f 20 64 69 73 |ent font|s to dis|
|00004300| 74 69 6e 67 75 69 73 68 | 20 69 6e 70 75 74 0d 20 |tinguish| input. |
|00004310| 20 20 20 20 20 20 20 66 | 72 6f 6d 20 6f 75 74 70 | f|rom outp|
|00004320| 75 74 2c 20 62 75 74 20 | 74 68 65 20 61 6d 6f 75 |ut, but |the amou|
|00004330| 6e 74 20 6f 66 20 4c 61 | 54 65 58 20 68 61 63 6b |nt of La|TeX hack|
|00004340| 69 6e 67 20 74 68 61 74 | 20 77 6f 75 6c 64 20 72 |ing that| would r|
|00004350| 65 71 75 69 72 65 0d 20 | 20 20 20 20 20 20 20 69 |equire. | i|
|00004360| 73 20 63 75 72 72 65 6e | 74 6c 79 20 62 65 79 6f |s curren|tly beyo|
|00004370| 6e 64 20 6d 79 20 61 62 | 69 6c 69 74 79 2e 0d 7d |nd my ab|ility..}|
|00004380| 0d 4e 6f 74 65 20 74 68 | 61 74 20 61 20 73 65 63 |.Note th|at a sec|
|00004390| 6f 6e 64 61 72 79 20 70 | 72 6f 6d 70 74 20 6f 6e |ondary p|rompt on|
|000043a0| 20 61 20 6c 69 6e 65 20 | 62 79 20 69 74 73 65 6c | a line |by itsel|
|000043b0| 66 20 69 6e 20 61 6e 20 | 65 78 61 6d 70 6c 65 20 |f in an |example |
|000043c0| 6d 65 61 6e 73 0d 79 6f | 75 20 6d 75 73 74 20 74 |means.yo|u must t|
|000043d0| 79 70 65 20 61 20 62 6c | 61 6e 6b 20 6c 69 6e 65 |ype a bl|ank line|
|000043e0| 3b 20 74 68 69 73 20 69 | 73 20 75 73 65 64 20 74 |; this i|s used t|
|000043f0| 6f 20 65 6e 64 20 61 20 | 6d 75 6c 74 69 2d 6c 69 |o end a |multi-li|
|00004400| 6e 65 20 63 6f 6d 6d 61 | 6e 64 2e 0d 0d 5c 73 65 |ne comma|nd...\se|
|00004410| 63 74 69 6f 6e 7b 55 73 | 69 6e 67 20 50 79 74 68 |ction{Us|ing Pyth|
|00004420| 6f 6e 20 61 73 20 61 20 | 43 61 6c 63 75 6c 61 74 |on as a |Calculat|
|00004430| 6f 72 7d 0d 0d 4c 65 74 | 27 73 20 74 72 79 20 73 |or}..Let|'s try s|
|00004440| 6f 6d 65 20 73 69 6d 70 | 6c 65 20 50 79 74 68 6f |ome simp|le Pytho|
|00004450| 6e 20 63 6f 6d 6d 61 6e | 64 73 2e 20 20 53 74 61 |n comman|ds. Sta|
|00004460| 72 74 20 74 68 65 20 69 | 6e 74 65 72 70 72 65 74 |rt the i|nterpret|
|00004470| 65 72 20 61 6e 64 20 77 | 61 69 74 0d 66 6f 72 20 |er and w|ait.for |
|00004480| 74 68 65 20 70 72 69 6d | 61 72 79 20 70 72 6f 6d |the prim|ary prom|
|00004490| 70 74 2c 20 7b 5c 74 74 | 20 3e 3e 3e 7d 2e 20 20 |pt, {\tt| >>>}. |
|000044a0| 28 49 74 20 73 68 6f 75 | 6c 64 6e 27 74 20 74 61 |(It shou|ldn't ta|
|000044b0| 6b 65 20 6c 6f 6e 67 2e | 29 0d 0d 5c 73 75 62 73 |ke long.|)..\subs|
|000044c0| 65 63 74 69 6f 6e 7b 4e | 75 6d 62 65 72 73 7d 0d |ection{N|umbers}.|
|000044d0| 0d 54 68 65 20 69 6e 74 | 65 72 70 72 65 74 65 72 |.The int|erpreter|
|000044e0| 20 61 63 74 73 20 61 73 | 20 61 20 73 69 6d 70 6c | acts as| a simpl|
|000044f0| 65 20 63 61 6c 63 75 6c | 61 74 6f 72 3a 20 79 6f |e calcul|ator: yo|
|00004500| 75 20 63 61 6e 20 74 79 | 70 65 20 61 6e 0d 65 78 |u can ty|pe an.ex|
|00004510| 70 72 65 73 73 69 6f 6e | 20 61 74 20 69 74 20 61 |pression| at it a|
|00004520| 6e 64 20 69 74 20 77 69 | 6c 6c 20 77 72 69 74 65 |nd it wi|ll write|
|00004530| 20 74 68 65 20 76 61 6c | 75 65 2e 20 20 45 78 70 | the val|ue. Exp|
|00004540| 72 65 73 73 69 6f 6e 20 | 73 79 6e 74 61 78 20 69 |ression |syntax i|
|00004550| 73 0d 73 74 72 61 69 67 | 68 74 66 6f 72 77 61 72 |s.straig|htforwar|
|00004560| 64 3a 20 74 68 65 20 6f | 70 65 72 61 74 6f 72 73 |d: the o|perators|
|00004570| 20 7b 5c 74 74 20 2b 7d | 2c 20 7b 5c 74 74 20 2d | {\tt +}|, {\tt -|
|00004580| 7d 2c 20 7b 5c 74 74 20 | 2a 7d 20 61 6e 64 20 7b |}, {\tt |*} and {|
|00004590| 5c 74 74 20 2f 7d 0d 77 | 6f 72 6b 20 6a 75 73 74 |\tt /}.w|ork just|
|000045a0| 20 6c 69 6b 65 20 69 6e | 20 6d 6f 73 74 20 6f 74 | like in| most ot|
|000045b0| 68 65 72 20 6c 61 6e 67 | 75 61 67 65 73 20 28 65 |her lang|uages (e|
|000045c0| 2e 67 2e 2c 20 50 61 73 | 63 61 6c 20 6f 72 20 43 |.g., Pas|cal or C|
|000045d0| 29 3b 20 70 61 72 65 6e | 74 68 65 73 65 73 0d 63 |); paren|theses.c|
|000045e0| 61 6e 20 62 65 20 75 73 | 65 64 20 66 6f 72 20 67 |an be us|ed for g|
|000045f0| 72 6f 75 70 69 6e 67 2e | 20 20 46 6f 72 20 65 78 |rouping.| For ex|
|00004600| 61 6d 70 6c 65 3a 0d 0d | 5c 62 63 6f 64 65 5c 62 |ample:..|\bcode\b|
|00004610| 65 67 69 6e 7b 76 65 72 | 62 61 74 69 6d 7d 0d 3e |egin{ver|batim}.>|
|00004620| 3e 3e 20 32 2b 32 0d 34 | 0d 3e 3e 3e 20 23 20 54 |>> 2+2.4|.>>> # T|
|00004630| 68 69 73 20 69 73 20 61 | 20 63 6f 6d 6d 65 6e 74 |his is a| comment|
|00004640| 0d 2e 2e 2e 20 32 2b 32 | 0d 34 0d 3e 3e 3e 20 32 |.... 2+2|.4.>>> 2|
|00004650| 2b 32 20 20 23 20 61 6e | 64 20 61 20 63 6f 6d 6d |+2 # an|d a comm|
|00004660| 65 6e 74 20 6f 6e 20 74 | 68 65 20 73 61 6d 65 20 |ent on t|he same |
|00004670| 6c 69 6e 65 20 61 73 20 | 63 6f 64 65 0d 34 0d 3e |line as |code.4.>|
|00004680| 3e 3e 20 28 35 30 2d 35 | 2a 36 29 2f 34 0d 35 0d |>> (50-5|*6)/4.5.|
|00004690| 3e 3e 3e 20 23 20 49 6e | 74 65 67 65 72 20 64 69 |>>> # In|teger di|
|000046a0| 76 69 73 69 6f 6e 20 72 | 65 74 75 72 6e 73 20 74 |vision r|eturns t|
|000046b0| 68 65 20 66 6c 6f 6f 72 | 3a 0d 2e 2e 2e 20 37 2f |he floor|:.... 7/|
|000046c0| 33 0d 32 0d 3e 3e 3e 20 | 37 2f 2d 33 0d 2d 33 0d |3.2.>>> |7/-3.-3.|
|000046d0| 3e 3e 3e 20 0d 5c 65 6e | 64 7b 76 65 72 62 61 74 |>>> .\en|d{verbat|
|000046e0| 69 6d 7d 5c 65 63 6f 64 | 65 0d 25 0d 4c 69 6b 65 |im}\ecod|e.%.Like|
|000046f0| 20 69 6e 20 43 2c 20 74 | 68 65 20 65 71 75 61 6c | in C, t|he equal|
|00004700| 20 73 69 67 6e 20 28 7b | 5c 74 74 20 3d 7d 29 20 | sign ({|\tt =}) |
|00004710| 69 73 20 75 73 65 64 20 | 74 6f 20 61 73 73 69 67 |is used |to assig|
|00004720| 6e 20 61 20 76 61 6c 75 | 65 20 74 6f 20 61 0d 76 |n a valu|e to a.v|
|00004730| 61 72 69 61 62 6c 65 2e | 20 20 54 68 65 20 76 61 |ariable.| The va|
|00004740| 6c 75 65 20 6f 66 20 61 | 6e 20 61 73 73 69 67 6e |lue of a|n assign|
|00004750| 6d 65 6e 74 20 69 73 20 | 6e 6f 74 20 77 72 69 74 |ment is |not writ|
|00004760| 74 65 6e 3a 0d 0d 5c 62 | 63 6f 64 65 5c 62 65 67 |ten:..\b|code\beg|
|00004770| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0d 3e 3e 3e |in{verba|tim}.>>>|
|00004780| 20 77 69 64 74 68 20 3d | 20 32 30 0d 3e 3e 3e 20 | width =| 20.>>> |
|00004790| 68 65 69 67 68 74 20 3d | 20 35 2a 39 0d 3e 3e 3e |height =| 5*9.>>>|
|000047a0| 20 77 69 64 74 68 20 2a | 20 68 65 69 67 68 74 0d | width *| height.|
|000047b0| 39 30 30 0d 3e 3e 3e 20 | 0d 5c 65 6e 64 7b 76 65 |900.>>> |.\end{ve|
|000047c0| 72 62 61 74 69 6d 7d 5c | 65 63 6f 64 65 0d 25 0d |rbatim}\|ecode.%.|
|000047d0| 41 20 76 61 6c 75 65 20 | 63 61 6e 20 62 65 20 61 |A value |can be a|
|000047e0| 73 73 69 67 6e 65 64 20 | 74 6f 20 73 65 76 65 72 |ssigned |to sever|
|000047f0| 61 6c 20 76 61 72 69 61 | 62 6c 65 73 20 73 69 6d |al varia|bles sim|
|00004800| 75 6c 74 61 6e 65 6f 75 | 73 6c 79 3a 0d 0d 5c 62 |ultaneou|sly:..\b|
|00004810| 63 6f 64 65 5c 62 65 67 | 69 6e 7b 76 65 72 62 61 |code\beg|in{verba|
|00004820| 74 69 6d 7d 0d 3e 3e 3e | 20 78 20 3d 20 79 20 3d |tim}.>>>| x = y =|
|00004830| 20 7a 20 3d 20 30 20 20 | 23 20 5a 65 72 6f 20 78 | z = 0 |# Zero x|
|00004840| 2c 20 79 20 61 6e 64 20 | 7a 0d 3e 3e 3e 20 78 0d |, y and |z.>>> x.|
|00004850| 30 0d 3e 3e 3e 20 79 0d | 30 0d 3e 3e 3e 20 7a 0d |0.>>> y.|0.>>> z.|
|00004860| 30 0d 3e 3e 3e 20 0d 5c | 65 6e 64 7b 76 65 72 62 |0.>>> .\|end{verb|
|00004870| 61 74 69 6d 7d 5c 65 63 | 6f 64 65 0d 25 0d 54 68 |atim}\ec|ode.%.Th|
|00004880| 65 72 65 20 69 73 20 66 | 75 6c 6c 20 73 75 70 70 |ere is f|ull supp|
|00004890| 6f 72 74 20 66 6f 72 20 | 66 6c 6f 61 74 69 6e 67 |ort for |floating|
|000048a0| 20 70 6f 69 6e 74 3b 20 | 6f 70 65 72 61 74 6f 72 | point; |operator|
|000048b0| 73 20 77 69 74 68 20 6d | 69 78 65 64 20 74 79 70 |s with m|ixed typ|
|000048c0| 65 0d 6f 70 65 72 61 6e | 64 73 20 63 6f 6e 76 65 |e.operan|ds conve|
|000048d0| 72 74 20 74 68 65 20 69 | 6e 74 65 67 65 72 20 6f |rt the i|nteger o|
|000048e0| 70 65 72 61 6e 64 20 74 | 6f 20 66 6c 6f 61 74 69 |perand t|o floati|
|000048f0| 6e 67 20 70 6f 69 6e 74 | 3a 0d 0d 5c 62 63 6f 64 |ng point|:..\bcod|
|00004900| 65 5c 62 65 67 69 6e 7b | 76 65 72 62 61 74 69 6d |e\begin{|verbatim|
|00004910| 7d 0d 3e 3e 3e 20 34 20 | 2a 20 32 2e 35 20 2f 20 |}.>>> 4 |* 2.5 / |
|00004920| 33 2e 33 0d 33 2e 30 33 | 30 33 30 33 30 33 30 33 |3.3.3.03|03030303|
|00004930| 0d 3e 3e 3e 20 37 2e 30 | 20 2f 20 32 0d 33 2e 35 |.>>> 7.0| / 2.3.5|
|00004940| 0d 3e 3e 3e 20 0d 5c 65 | 6e 64 7b 76 65 72 62 61 |.>>> .\e|nd{verba|
|00004950| 74 69 6d 7d 5c 65 63 6f | 64 65 0d 0d 5c 73 75 62 |tim}\eco|de..\sub|
|00004960| 73 65 63 74 69 6f 6e 7b | 53 74 72 69 6e 67 73 7d |section{|Strings}|
|00004970| 0d 0d 42 65 73 69 64 65 | 73 20 6e 75 6d 62 65 72 |..Beside|s number|
|00004980| 73 2c 20 50 79 74 68 6f | 6e 20 63 61 6e 20 61 6c |s, Pytho|n can al|
|00004990| 73 6f 20 6d 61 6e 69 70 | 75 6c 61 74 65 20 73 74 |so manip|ulate st|
|000049a0| 72 69 6e 67 73 2c 20 65 | 6e 63 6c 6f 73 65 64 20 |rings, e|nclosed |
|000049b0| 69 6e 0d 73 69 6e 67 6c | 65 20 71 75 6f 74 65 73 |in.singl|e quotes|
|000049c0| 20 6f 72 20 64 6f 75 62 | 6c 65 20 71 75 6f 74 65 | or doub|le quote|
|000049d0| 73 3a 0d 0d 5c 62 63 6f | 64 65 5c 62 65 67 69 6e |s:..\bco|de\begin|
|000049e0| 7b 76 65 72 62 61 74 69 | 6d 7d 0d 3e 3e 3e 20 27 |{verbati|m}.>>> '|
|000049f0| 73 70 61 6d 20 65 67 67 | 73 27 0d 27 73 70 61 6d |spam egg|s'.'spam|
|00004a00| 20 65 67 67 73 27 0d 3e | 3e 3e 20 27 64 6f 65 73 | eggs'.>|>> 'does|
|00004a10| 6e 5c 27 74 27 0d 22 64 | 6f 65 73 6e 27 74 22 0d |n\'t'."d|oesn't".|
|00004a20| 3e 3e 3e 20 22 64 6f 65 | 73 6e 27 74 22 0d 22 64 |>>> "doe|sn't"."d|
|00004a30| 6f 65 73 6e 27 74 22 0d | 3e 3e 3e 20 27 22 59 65 |oesn't".|>>> '"Ye|
|00004a40| 73 2c 22 20 68 65 20 73 | 61 69 64 2e 27 0d 27 22 |s," he s|aid.'.'"|
|00004a50| 59 65 73 2c 22 20 68 65 | 20 73 61 69 64 2e 27 0d |Yes," he| said.'.|
|00004a60| 3e 3e 3e 20 22 5c 22 59 | 65 73 2c 5c 22 20 68 65 |>>> "\"Y|es,\" he|
|00004a70| 20 73 61 69 64 2e 22 0d | 27 22 59 65 73 2c 22 20 | said.".|'"Yes," |
|00004a80| 68 65 20 73 61 69 64 2e | 27 0d 3e 3e 3e 20 27 22 |he said.|'.>>> '"|
|00004a90| 49 73 6e 5c 27 74 2c 22 | 20 73 68 65 20 73 61 69 |Isn\'t,"| she sai|
|00004aa0| 64 2e 27 0d 27 22 49 73 | 6e 5c 27 74 2c 22 20 73 |d.'.'"Is|n\'t," s|
|00004ab0| 68 65 20 73 61 69 64 2e | 27 0d 3e 3e 3e 20 0d 5c |he said.|'.>>> .\|
|00004ac0| 65 6e 64 7b 76 65 72 62 | 61 74 69 6d 7d 5c 65 63 |end{verb|atim}\ec|
|00004ad0| 6f 64 65 0d 25 0d 53 74 | 72 69 6e 67 73 20 61 72 |ode.%.St|rings ar|
|00004ae0| 65 20 77 72 69 74 74 65 | 6e 20 74 68 65 20 73 61 |e writte|n the sa|
|00004af0| 6d 65 20 77 61 79 20 61 | 73 20 74 68 65 79 20 61 |me way a|s they a|
|00004b00| 72 65 20 74 79 70 65 64 | 20 66 6f 72 20 69 6e 70 |re typed| for inp|
|00004b10| 75 74 3a 20 69 6e 73 69 | 64 65 0d 71 75 6f 74 65 |ut: insi|de.quote|
|00004b20| 73 20 61 6e 64 20 77 69 | 74 68 20 71 75 6f 74 65 |s and wi|th quote|
|00004b30| 73 20 61 6e 64 20 6f 74 | 68 65 72 20 66 75 6e 6e |s and ot|her funn|
|00004b40| 79 20 63 68 61 72 61 63 | 74 65 72 73 20 65 73 63 |y charac|ters esc|
|00004b50| 61 70 65 64 20 62 79 20 | 62 61 63 6b 73 6c 61 73 |aped by |backslas|
|00004b60| 68 65 73 2c 0d 74 6f 20 | 73 68 6f 77 20 74 68 65 |hes,.to |show the|
|00004b70| 20 70 72 65 63 69 73 65 | 20 76 61 6c 75 65 2e 20 | precise| value. |
|00004b80| 20 54 68 65 20 73 74 72 | 69 6e 67 20 69 73 20 65 | The str|ing is e|
|00004b90| 6e 63 6c 6f 73 65 64 20 | 69 6e 20 64 6f 75 62 6c |nclosed |in doubl|
|00004ba0| 65 20 71 75 6f 74 65 73 | 20 69 66 0d 74 68 65 20 |e quotes| if.the |
|00004bb0| 73 74 72 69 6e 67 20 63 | 6f 6e 74 61 69 6e 73 20 |string c|ontains |
|00004bc0| 61 20 73 69 6e 67 6c 65 | 20 71 75 6f 74 65 20 61 |a single| quote a|
|00004bd0| 6e 64 20 6e 6f 20 64 6f | 75 62 6c 65 20 71 75 6f |nd no do|uble quo|
|00004be0| 74 65 73 2c 20 65 6c 73 | 65 20 69 74 27 73 0d 65 |tes, els|e it's.e|
|00004bf0| 6e 63 6c 6f 73 65 64 20 | 69 6e 20 73 69 6e 67 6c |nclosed |in singl|
|00004c00| 65 20 71 75 6f 74 65 73 | 2e 20 20 28 54 68 65 20 |e quotes|. (The |
|00004c10| 7b 5c 74 74 20 70 72 69 | 6e 74 7d 20 73 74 61 74 |{\tt pri|nt} stat|
|00004c20| 65 6d 65 6e 74 2c 20 64 | 65 73 63 72 69 62 65 64 |ement, d|escribed|
|00004c30| 20 6c 61 74 65 72 2c 0d | 63 61 6e 20 62 65 20 75 | later,.|can be u|
|00004c40| 73 65 64 20 74 6f 20 77 | 72 69 74 65 20 73 74 72 |sed to w|rite str|
|00004c50| 69 6e 67 73 20 77 69 74 | 68 6f 75 74 20 71 75 6f |ings wit|hout quo|
|00004c60| 74 65 73 20 6f 72 20 65 | 73 63 61 70 65 73 2e 29 |tes or e|scapes.)|
|00004c70| 0d 0d 53 74 72 69 6e 67 | 73 20 63 61 6e 20 62 65 |..String|s can be|
|00004c80| 20 63 6f 6e 63 61 74 65 | 6e 61 74 65 64 20 28 67 | concate|nated (g|
|00004c90| 6c 75 65 64 20 74 6f 67 | 65 74 68 65 72 29 20 77 |lued tog|ether) w|
|00004ca0| 69 74 68 20 74 68 65 20 | 7b 5c 74 74 20 2b 7d 0d |ith the |{\tt +}.|
|00004cb0| 6f 70 65 72 61 74 6f 72 | 2c 20 61 6e 64 20 72 65 |operator|, and re|
|00004cc0| 70 65 61 74 65 64 20 77 | 69 74 68 20 7b 5c 74 74 |peated w|ith {\tt|
|00004cd0| 20 2a 7d 3a 0d 0d 5c 62 | 63 6f 64 65 5c 62 65 67 | *}:..\b|code\beg|
|00004ce0| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0d 3e 3e 3e |in{verba|tim}.>>>|
|00004cf0| 20 77 6f 72 64 20 3d 20 | 27 48 65 6c 70 27 20 2b | word = |'Help' +|
|00004d00| 20 27 41 27 0d 3e 3e 3e | 20 77 6f 72 64 0d 27 48 | 'A'.>>>| word.'H|
|00004d10| 65 6c 70 41 27 0d 3e 3e | 3e 20 27 3c 27 20 2b 20 |elpA'.>>|> '<' + |
|00004d20| 77 6f 72 64 2a 35 20 2b | 20 27 3e 27 0d 27 3c 48 |word*5 +| '>'.'<H|
|00004d30| 65 6c 70 41 48 65 6c 70 | 41 48 65 6c 70 41 48 65 |elpAHelp|AHelpAHe|
|00004d40| 6c 70 41 48 65 6c 70 41 | 3e 27 0d 3e 3e 3e 20 0d |lpAHelpA|>'.>>> .|
|00004d50| 5c 65 6e 64 7b 76 65 72 | 62 61 74 69 6d 7d 5c 65 |\end{ver|batim}\e|
|00004d60| 63 6f 64 65 0d 25 0d 53 | 74 72 69 6e 67 73 20 63 |code.%.S|trings c|
|00004d70| 61 6e 20 62 65 20 73 75 | 62 73 63 72 69 70 74 65 |an be su|bscripte|
|00004d80| 64 20 28 69 6e 64 65 78 | 65 64 29 3b 20 6c 69 6b |d (index|ed); lik|
|00004d90| 65 20 69 6e 20 43 2c 20 | 74 68 65 20 66 69 72 73 |e in C, |the firs|
|00004da0| 74 20 63 68 61 72 61 63 | 74 65 72 20 6f 66 0d 61 |t charac|ter of.a|
|00004db0| 20 73 74 72 69 6e 67 20 | 68 61 73 20 73 75 62 73 | string |has subs|
|00004dc0| 63 72 69 70 74 20 28 69 | 6e 64 65 78 29 20 30 2e |cript (i|ndex) 0.|
|00004dd0| 0d 0d 54 68 65 72 65 20 | 69 73 20 6e 6f 20 73 65 |..There |is no se|
|00004de0| 70 61 72 61 74 65 20 63 | 68 61 72 61 63 74 65 72 |parate c|haracter|
|00004df0| 20 74 79 70 65 3b 20 61 | 20 63 68 61 72 61 63 74 | type; a| charact|
|00004e00| 65 72 20 69 73 20 73 69 | 6d 70 6c 79 20 61 20 73 |er is si|mply a s|
|00004e10| 74 72 69 6e 67 20 6f 66 | 0d 73 69 7a 65 20 6f 6e |tring of|.size on|
|00004e20| 65 2e 20 20 4c 69 6b 65 | 20 69 6e 20 49 63 6f 6e |e. Like| in Icon|
|00004e30| 2c 20 73 75 62 73 74 72 | 69 6e 67 73 20 63 61 6e |, substr|ings can|
|00004e40| 20 62 65 20 73 70 65 63 | 69 66 69 65 64 20 77 69 | be spec|ified wi|
|00004e50| 74 68 20 74 68 65 20 7b | 5c 65 6d 0d 73 6c 69 63 |th the {|\em.slic|
|00004e60| 65 7d 20 6e 6f 74 61 74 | 69 6f 6e 3a 20 74 77 6f |e} notat|ion: two|
|00004e70| 20 69 6e 64 69 63 65 73 | 20 73 65 70 61 72 61 74 | indices| separat|
|00004e80| 65 64 20 62 79 20 61 20 | 63 6f 6c 6f 6e 2e 0d 0d |ed by a |colon...|
|00004e90| 5c 62 63 6f 64 65 5c 62 | 65 67 69 6e 7b 76 65 72 |\bcode\b|egin{ver|
|00004ea0| 62 61 74 69 6d 7d 0d 3e | 3e 3e 20 77 6f 72 64 5b |batim}.>|>> word[|
|00004eb0| 34 5d 0d 27 41 27 0d 3e | 3e 3e 20 77 6f 72 64 5b |4].'A'.>|>> word[|
|00004ec0| 30 3a 32 5d 0d 27 48 65 | 27 0d 3e 3e 3e 20 77 6f |0:2].'He|'.>>> wo|
|00004ed0| 72 64 5b 32 3a 34 5d 0d | 27 6c 70 27 0d 3e 3e 3e |rd[2:4].|'lp'.>>>|
|00004ee0| 20 0d 5c 65 6e 64 7b 76 | 65 72 62 61 74 69 6d 7d | .\end{v|erbatim}|
|00004ef0| 5c 65 63 6f 64 65 0d 25 | 0d 53 6c 69 63 65 20 69 |\ecode.%|.Slice i|
|00004f00| 6e 64 69 63 65 73 20 68 | 61 76 65 20 75 73 65 66 |ndices h|ave usef|
|00004f10| 75 6c 20 64 65 66 61 75 | 6c 74 73 3b 20 61 6e 20 |ul defau|lts; an |
|00004f20| 6f 6d 69 74 74 65 64 20 | 66 69 72 73 74 20 69 6e |omitted |first in|
|00004f30| 64 65 78 20 64 65 66 61 | 75 6c 74 73 20 74 6f 0d |dex defa|ults to.|
|00004f40| 7a 65 72 6f 2c 20 61 6e | 20 6f 6d 69 74 74 65 64 |zero, an| omitted|
|00004f50| 20 73 65 63 6f 6e 64 20 | 69 6e 64 65 78 20 64 65 | second |index de|
|00004f60| 66 61 75 6c 74 73 20 74 | 6f 20 74 68 65 20 73 69 |faults t|o the si|
|00004f70| 7a 65 20 6f 66 20 74 68 | 65 20 73 74 72 69 6e 67 |ze of th|e string|
|00004f80| 20 62 65 69 6e 67 0d 73 | 6c 69 63 65 64 2e 0d 0d | being.s|liced...|
|00004f90| 5c 62 63 6f 64 65 5c 62 | 65 67 69 6e 7b 76 65 72 |\bcode\b|egin{ver|
|00004fa0| 62 61 74 69 6d 7d 0d 3e | 3e 3e 20 77 6f 72 64 5b |batim}.>|>> word[|
|00004fb0| 3a 32 5d 20 20 20 20 23 | 20 54 68 65 20 66 69 72 |:2] #| The fir|
|00004fc0| 73 74 20 74 77 6f 20 63 | 68 61 72 61 63 74 65 72 |st two c|haracter|
|00004fd0| 73 0d 27 48 65 27 0d 3e | 3e 3e 20 77 6f 72 64 5b |s.'He'.>|>> word[|
|00004fe0| 32 3a 5d 20 20 20 20 23 | 20 41 6c 6c 20 62 75 74 |2:] #| All but|
|00004ff0| 20 74 68 65 20 66 69 72 | 73 74 20 74 77 6f 20 63 | the fir|st two c|
|00005000| 68 61 72 61 63 74 65 72 | 73 0d 27 6c 70 41 27 0d |haracter|s.'lpA'.|
|00005010| 3e 3e 3e 0d 5c 65 6e 64 | 7b 76 65 72 62 61 74 69 |>>>.\end|{verbati|
|00005020| 6d 7d 5c 65 63 6f 64 65 | 0d 25 0d 48 65 72 65 27 |m}\ecode|.%.Here'|
|00005030| 73 20 61 20 75 73 65 66 | 75 6c 20 69 6e 76 61 72 |s a usef|ul invar|
|00005040| 69 61 6e 74 20 6f 66 20 | 73 6c 69 63 65 20 6f 70 |iant of |slice op|
|00005050| 65 72 61 74 69 6f 6e 73 | 3a 20 5c 76 65 72 62 5c |erations|: \verb\|
|00005060| 73 5b 3a 69 5d 20 2b 20 | 73 5b 69 3a 5d 5c 0d 65 |s[:i] + |s[i:]\.e|
|00005070| 71 75 61 6c 73 20 5c 76 | 65 72 62 5c 73 5c 2e 0d |quals \v|erb\s\..|
|00005080| 0d 5c 62 63 6f 64 65 5c | 62 65 67 69 6e 7b 76 65 |.\bcode\|begin{ve|
|00005090| 72 62 61 74 69 6d 7d 0d | 3e 3e 3e 20 77 6f 72 64 |rbatim}.|>>> word|
|000050a0| 5b 3a 32 5d 20 2b 20 77 | 6f 72 64 5b 32 3a 5d 0d |[:2] + w|ord[2:].|
|000050b0| 27 48 65 6c 70 41 27 0d | 3e 3e 3e 20 77 6f 72 64 |'HelpA'.|>>> word|
|000050c0| 5b 3a 33 5d 20 2b 20 77 | 6f 72 64 5b 33 3a 5d 0d |[:3] + w|ord[3:].|
|000050d0| 27 48 65 6c 70 41 27 0d | 3e 3e 3e 20 0d 5c 65 6e |'HelpA'.|>>> .\en|
|000050e0| 64 7b 76 65 72 62 61 74 | 69 6d 7d 5c 65 63 6f 64 |d{verbat|im}\ecod|
|000050f0| 65 0d 25 0d 44 65 67 65 | 6e 65 72 61 74 65 20 73 |e.%.Dege|nerate s|
|00005100| 6c 69 63 65 20 69 6e 64 | 69 63 65 73 20 61 72 65 |lice ind|ices are|
|00005110| 20 68 61 6e 64 6c 65 64 | 20 67 72 61 63 65 66 75 | handled| gracefu|
|00005120| 6c 6c 79 3a 20 61 6e 20 | 69 6e 64 65 78 20 74 68 |lly: an |index th|
|00005130| 61 74 20 69 73 20 74 6f | 6f 0d 6c 61 72 67 65 20 |at is to|o.large |
|00005140| 69 73 20 72 65 70 6c 61 | 63 65 64 20 62 79 20 74 |is repla|ced by t|
|00005150| 68 65 20 73 74 72 69 6e | 67 20 73 69 7a 65 2c 20 |he strin|g size, |
|00005160| 61 6e 20 75 70 70 65 72 | 20 62 6f 75 6e 64 20 73 |an upper| bound s|
|00005170| 6d 61 6c 6c 65 72 20 74 | 68 61 6e 20 74 68 65 0d |maller t|han the.|
|00005180| 6c 6f 77 65 72 20 62 6f | 75 6e 64 20 72 65 74 75 |lower bo|und retu|
|00005190| 72 6e 73 20 61 6e 20 65 | 6d 70 74 79 20 73 74 72 |rns an e|mpty str|
|000051a0| 69 6e 67 2e 0d 0d 5c 62 | 63 6f 64 65 5c 62 65 67 |ing...\b|code\beg|
|000051b0| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0d 3e 3e 3e |in{verba|tim}.>>>|
|000051c0| 20 77 6f 72 64 5b 31 3a | 31 30 30 5d 0d 27 65 6c | word[1:|100].'el|
|000051d0| 70 41 27 0d 3e 3e 3e 20 | 77 6f 72 64 5b 31 30 3a |pA'.>>> |word[10:|
|000051e0| 5d 0d 27 27 0d 3e 3e 3e | 20 77 6f 72 64 5b 32 3a |].''.>>>| word[2:|
|000051f0| 31 5d 0d 27 27 0d 3e 3e | 3e 20 0d 5c 65 6e 64 7b |1].''.>>|> .\end{|
|00005200| 76 65 72 62 61 74 69 6d | 7d 5c 65 63 6f 64 65 0d |verbatim|}\ecode.|
|00005210| 25 0d 49 6e 64 69 63 65 | 73 20 6d 61 79 20 62 65 |%.Indice|s may be|
|00005220| 20 6e 65 67 61 74 69 76 | 65 20 6e 75 6d 62 65 72 | negativ|e number|
|00005230| 73 2c 20 74 6f 20 73 74 | 61 72 74 20 63 6f 75 6e |s, to st|art coun|
|00005240| 74 69 6e 67 20 66 72 6f | 6d 20 74 68 65 20 72 69 |ting fro|m the ri|
|00005250| 67 68 74 2e 0d 46 6f 72 | 20 65 78 61 6d 70 6c 65 |ght..For| example|
|00005260| 3a 0d 0d 5c 62 63 6f 64 | 65 5c 62 65 67 69 6e 7b |:..\bcod|e\begin{|
|00005270| 76 65 72 62 61 74 69 6d | 7d 0d 3e 3e 3e 20 77 6f |verbatim|}.>>> wo|
|00005280| 72 64 5b 2d 31 5d 20 20 | 20 20 20 23 20 54 68 65 |rd[-1] | # The|
|00005290| 20 6c 61 73 74 20 63 68 | 61 72 61 63 74 65 72 0d | last ch|aracter.|
|000052a0| 27 41 27 0d 3e 3e 3e 20 | 77 6f 72 64 5b 2d 32 5d |'A'.>>> |word[-2]|
|000052b0| 20 20 20 20 20 23 20 54 | 68 65 20 6c 61 73 74 2d | # T|he last-|
|000052c0| 62 75 74 2d 6f 6e 65 20 | 63 68 61 72 61 63 74 65 |but-one |characte|
|000052d0| 72 0d 27 70 27 0d 3e 3e | 3e 20 77 6f 72 64 5b 2d |r.'p'.>>|> word[-|
|000052e0| 32 3a 5d 20 20 20 20 23 | 20 54 68 65 20 6c 61 73 |2:] #| The las|
|000052f0| 74 20 74 77 6f 20 63 68 | 61 72 61 63 74 65 72 73 |t two ch|aracters|
|00005300| 0d 27 70 41 27 0d 3e 3e | 3e 20 77 6f 72 64 5b 3a |.'pA'.>>|> word[:|
|00005310| 2d 32 5d 20 20 20 20 23 | 20 41 6c 6c 20 62 75 74 |-2] #| All but|
|00005320| 20 74 68 65 20 6c 61 73 | 74 20 74 77 6f 20 63 68 | the las|t two ch|
|00005330| 61 72 61 63 74 65 72 73 | 0d 27 48 65 6c 27 0d 3e |aracters|.'Hel'.>|
|00005340| 3e 3e 0d 5c 65 6e 64 7b | 76 65 72 62 61 74 69 6d |>>.\end{|verbatim|
|00005350| 7d 5c 65 63 6f 64 65 0d | 25 0d 42 75 74 20 6e 6f |}\ecode.|%.But no|
|00005360| 74 65 20 74 68 61 74 20 | 2d 30 20 69 73 20 72 65 |te that |-0 is re|
|00005370| 61 6c 6c 79 20 74 68 65 | 20 73 61 6d 65 20 61 73 |ally the| same as|
|00005380| 20 30 2c 20 73 6f 20 69 | 74 20 64 6f 65 73 20 6e | 0, so i|t does n|
|00005390| 6f 74 20 63 6f 75 6e 74 | 20 66 72 6f 6d 0d 74 68 |ot count| from.th|
|000053a0| 65 20 72 69 67 68 74 21 | 0d 0d 5c 62 63 6f 64 65 |e right!|..\bcode|
|000053b0| 5c 62 65 67 69 6e 7b 76 | 65 72 62 61 74 69 6d 7d |\begin{v|erbatim}|
|000053c0| 0d 3e 3e 3e 20 77 6f 72 | 64 5b 2d 30 5d 20 20 20 |.>>> wor|d[-0] |
|000053d0| 20 20 23 20 28 73 69 6e | 63 65 20 2d 30 20 65 71 | # (sin|ce -0 eq|
|000053e0| 75 61 6c 73 20 30 29 0d | 27 48 27 0d 3e 3e 3e 0d |uals 0).|'H'.>>>.|
|000053f0| 5c 65 6e 64 7b 76 65 72 | 62 61 74 69 6d 7d 5c 65 |\end{ver|batim}\e|
|00005400| 63 6f 64 65 0d 25 0d 4f | 75 74 2d 6f 66 2d 72 61 |code.%.O|ut-of-ra|
|00005410| 6e 67 65 20 6e 65 67 61 | 74 69 76 65 20 73 6c 69 |nge nega|tive sli|
|00005420| 63 65 20 69 6e 64 69 63 | 65 73 20 61 72 65 20 74 |ce indic|es are t|
|00005430| 72 75 6e 63 61 74 65 64 | 2c 20 62 75 74 20 64 6f |runcated|, but do|
|00005440| 6e 27 74 20 74 72 79 20 | 74 68 69 73 0d 66 6f 72 |n't try |this.for|
|00005450| 20 73 69 6e 67 6c 65 2d | 65 6c 65 6d 65 6e 74 20 | single-|element |
|00005460| 28 6e 6f 6e 2d 73 6c 69 | 63 65 29 20 69 6e 64 69 |(non-sli|ce) indi|
|00005470| 63 65 73 3a 0d 0d 5c 62 | 63 6f 64 65 5c 62 65 67 |ces:..\b|code\beg|
|00005480| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0d 3e 3e 3e |in{verba|tim}.>>>|
|00005490| 20 77 6f 72 64 5b 2d 31 | 30 30 3a 5d 0d 27 48 65 | word[-1|00:].'He|
|000054a0| 6c 70 41 27 0d 3e 3e 3e | 20 77 6f 72 64 5b 2d 31 |lpA'.>>>| word[-1|
|000054b0| 30 5d 20 20 20 20 23 20 | 65 72 72 6f 72 0d 54 72 |0] # |error.Tr|
|000054c0| 61 63 65 62 61 63 6b 20 | 28 69 6e 6e 65 72 6d 6f |aceback |(innermo|
|000054d0| 73 74 20 6c 61 73 74 29 | 3a 0d 20 20 46 69 6c 65 |st last)|:. File|
|000054e0| 20 22 3c 73 74 64 69 6e | 3e 22 2c 20 6c 69 6e 65 | "<stdin|>", line|
|000054f0| 20 31 0d 49 6e 64 65 78 | 45 72 72 6f 72 3a 20 73 | 1.Index|Error: s|
|00005500| 74 72 69 6e 67 20 69 6e | 64 65 78 20 6f 75 74 20 |tring in|dex out |
|00005510| 6f 66 20 72 61 6e 67 65 | 0d 3e 3e 3e 20 0d 5c 65 |of range|.>>> .\e|
|00005520| 6e 64 7b 76 65 72 62 61 | 74 69 6d 7d 5c 65 63 6f |nd{verba|tim}\eco|
|00005530| 64 65 0d 25 0d 54 68 65 | 20 62 65 73 74 20 77 61 |de.%.The| best wa|
|00005540| 79 20 74 6f 20 72 65 6d | 65 6d 62 65 72 20 68 6f |y to rem|ember ho|
|00005550| 77 20 73 6c 69 63 65 73 | 20 77 6f 72 6b 20 69 73 |w slices| work is|
|00005560| 20 74 6f 20 74 68 69 6e | 6b 20 6f 66 20 74 68 65 | to thin|k of the|
|00005570| 20 69 6e 64 69 63 65 73 | 20 61 73 0d 70 6f 69 6e | indices| as.poin|
|00005580| 74 69 6e 67 20 7b 5c 65 | 6d 20 62 65 74 77 65 65 |ting {\e|m betwee|
|00005590| 6e 7d 20 63 68 61 72 61 | 63 74 65 72 73 2c 20 77 |n} chara|cters, w|
|000055a0| 69 74 68 20 74 68 65 20 | 6c 65 66 74 20 65 64 67 |ith the |left edg|
|000055b0| 65 20 6f 66 20 74 68 65 | 20 66 69 72 73 74 0d 63 |e of the| first.c|
|000055c0| 68 61 72 61 63 74 65 72 | 20 6e 75 6d 62 65 72 65 |haracter| numbere|
|000055d0| 64 20 30 2e 20 20 54 68 | 65 6e 20 74 68 65 20 72 |d 0. Th|en the r|
|000055e0| 69 67 68 74 20 65 64 67 | 65 20 6f 66 20 74 68 65 |ight edg|e of the|
|000055f0| 20 6c 61 73 74 20 63 68 | 61 72 61 63 74 65 72 20 | last ch|aracter |
|00005600| 6f 66 20 61 0d 73 74 72 | 69 6e 67 20 6f 66 20 7b |of a.str|ing of {|
|00005610| 5c 74 74 20 6e 7d 20 63 | 68 61 72 61 63 74 65 72 |\tt n} c|haracter|
|00005620| 73 20 68 61 73 20 69 6e | 64 65 78 20 7b 5c 74 74 |s has in|dex {\tt|
|00005630| 20 6e 7d 2c 20 66 6f 72 | 20 65 78 61 6d 70 6c 65 | n}, for| example|
|00005640| 3a 0d 0d 5c 62 63 6f 64 | 65 5c 62 65 67 69 6e 7b |:..\bcod|e\begin{|
|00005650| 76 65 72 62 61 74 69 6d | 7d 0d 20 2b 2d 2d 2d 2b |verbatim|}. +---+|
|00005660| 2d 2d 2d 2b 2d 2d 2d 2b | 2d 2d 2d 2b 2d 2d 2d 2b |---+---+|---+---+|
|00005670| 20 0d 20 7c 20 48 20 7c | 20 65 20 7c 20 6c 20 7c | . | H || e | l ||
|00005680| 20 70 20 7c 20 41 20 7c | 0d 20 2b 2d 2d 2d 2b 2d | p | A ||. +---+-|
|00005690| 2d 2d 2b 2d 2d 2d 2b 2d | 2d 2d 2b 2d 2d 2d 2b 20 |--+---+-|--+---+ |
|000056a0| 0d 20 30 20 20 20 31 20 | 20 20 32 20 20 20 33 20 |. 0 1 | 2 3 |
|000056b0| 20 20 34 20 20 20 35 20 | 0d 2d 35 20 20 2d 34 20 | 4 5 |.-5 -4 |
|000056c0| 20 2d 33 20 20 2d 32 20 | 20 2d 31 0d 5c 65 6e 64 | -3 -2 | -1.\end|
|000056d0| 7b 76 65 72 62 61 74 69 | 6d 7d 5c 65 63 6f 64 65 |{verbati|m}\ecode|
|000056e0| 0d 25 0d 54 68 65 20 66 | 69 72 73 74 20 72 6f 77 |.%.The f|irst row|
|000056f0| 20 6f 66 20 6e 75 6d 62 | 65 72 73 20 67 69 76 65 | of numb|ers give|
|00005700| 73 20 74 68 65 20 70 6f | 73 69 74 69 6f 6e 20 6f |s the po|sition o|
|00005710| 66 20 74 68 65 20 69 6e | 64 69 63 65 73 20 30 2e |f the in|dices 0.|
|00005720| 2e 2e 35 20 69 6e 0d 74 | 68 65 20 73 74 72 69 6e |..5 in.t|he strin|
|00005730| 67 3b 20 74 68 65 20 73 | 65 63 6f 6e 64 20 72 6f |g; the s|econd ro|
|00005740| 77 20 67 69 76 65 73 20 | 74 68 65 20 63 6f 72 72 |w gives |the corr|
|00005750| 65 73 70 6f 6e 64 69 6e | 67 20 6e 65 67 61 74 69 |espondin|g negati|
|00005760| 76 65 20 69 6e 64 69 63 | 65 73 2e 0d 54 68 65 20 |ve indic|es..The |
|00005770| 73 6c 69 63 65 20 66 72 | 6f 6d 20 5c 76 65 72 62 |slice fr|om \verb|
|00005780| 5c 69 5c 20 74 6f 20 5c | 76 65 72 62 5c 6a 5c 20 |\i\ to \|verb\j\ |
|00005790| 63 6f 6e 73 69 73 74 73 | 20 6f 66 20 61 6c 6c 20 |consists| of all |
|000057a0| 63 68 61 72 61 63 74 65 | 72 73 20 62 65 74 77 65 |characte|rs betwe|
|000057b0| 65 6e 0d 74 68 65 20 65 | 64 67 65 73 20 6c 61 62 |en.the e|dges lab|
|000057c0| 65 6c 65 64 20 5c 76 65 | 72 62 5c 69 5c 20 61 6e |eled \ve|rb\i\ an|
|000057d0| 64 20 5c 76 65 72 62 5c | 6a 5c 2c 20 72 65 73 70 |d \verb\|j\, resp|
|000057e0| 65 63 74 69 76 65 6c 79 | 2e 0d 0d 46 6f 72 20 6e |ectively|...For n|
|000057f0| 6f 6e 6e 65 67 61 74 69 | 76 65 20 69 6e 64 69 63 |onnegati|ve indic|
|00005800| 65 73 2c 20 74 68 65 20 | 6c 65 6e 67 74 68 20 6f |es, the |length o|
|00005810| 66 20 61 20 73 6c 69 63 | 65 20 69 73 20 74 68 65 |f a slic|e is the|
|00005820| 20 64 69 66 66 65 72 65 | 6e 63 65 20 6f 66 0d 74 | differe|nce of.t|
|00005830| 68 65 20 69 6e 64 69 63 | 65 73 2c 20 69 66 20 62 |he indic|es, if b|
|00005840| 6f 74 68 20 61 72 65 20 | 77 69 74 68 69 6e 20 62 |oth are |within b|
|00005850| 6f 75 6e 64 73 2c 20 65 | 2e 67 2e 2c 20 74 68 65 |ounds, e|.g., the|
|00005860| 20 6c 65 6e 67 74 68 20 | 6f 66 0d 5c 76 65 72 62 | length |of.\verb|
|00005870| 5c 77 6f 72 64 5b 31 3a | 33 5d 5c 20 69 73 20 32 |\word[1:|3]\ is 2|
|00005880| 2e 0d 0d 54 68 65 20 62 | 75 69 6c 74 2d 69 6e 20 |...The b|uilt-in |
|00005890| 66 75 6e 63 74 69 6f 6e | 20 7b 5c 74 74 20 6c 65 |function| {\tt le|
|000058a0| 6e 28 29 7d 20 72 65 74 | 75 72 6e 73 20 74 68 65 |n()} ret|urns the|
|000058b0| 20 6c 65 6e 67 74 68 20 | 6f 66 20 61 20 73 74 72 | length |of a str|
|000058c0| 69 6e 67 3a 0d 0d 5c 62 | 63 6f 64 65 5c 62 65 67 |ing:..\b|code\beg|
|000058d0| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0d 3e 3e 3e |in{verba|tim}.>>>|
|000058e0| 20 73 20 3d 20 27 73 75 | 70 65 72 63 61 6c 69 66 | s = 'su|percalif|
|000058f0| 72 61 67 69 6c 69 73 74 | 69 63 65 78 70 69 61 6c |ragilist|icexpial|
|00005900| 69 64 6f 63 69 6f 75 73 | 27 0d 3e 3e 3e 20 6c 65 |idocious|'.>>> le|
|00005910| 6e 28 73 29 0d 33 34 0d | 3e 3e 3e 20 0d 5c 65 6e |n(s).34.|>>> .\en|
|00005920| 64 7b 76 65 72 62 61 74 | 69 6d 7d 5c 65 63 6f 64 |d{verbat|im}\ecod|
|00005930| 65 0d 0d 5c 73 75 62 73 | 65 63 74 69 6f 6e 7b 4c |e..\subs|ection{L|
|00005940| 69 73 74 73 7d 0d 0d 50 | 79 74 68 6f 6e 20 6b 6e |ists}..P|ython kn|
|00005950| 6f 77 73 20 61 20 6e 75 | 6d 62 65 72 20 6f 66 20 |ows a nu|mber of |
|00005960| 7b 5c 65 6d 20 63 6f 6d | 70 6f 75 6e 64 7d 20 64 |{\em com|pound} d|
|00005970| 61 74 61 20 74 79 70 65 | 73 2c 20 75 73 65 64 20 |ata type|s, used |
|00005980| 74 6f 20 67 72 6f 75 70 | 0d 74 6f 67 65 74 68 65 |to group|.togethe|
|00005990| 72 20 6f 74 68 65 72 20 | 76 61 6c 75 65 73 2e 20 |r other |values. |
|000059a0| 20 54 68 65 20 6d 6f 73 | 74 20 76 65 72 73 61 74 | The mos|t versat|
|000059b0| 69 6c 65 20 69 73 20 74 | 68 65 20 7b 5c 65 6d 20 |ile is t|he {\em |
|000059c0| 6c 69 73 74 7d 2c 20 77 | 68 69 63 68 0d 63 61 6e |list}, w|hich.can|
|000059d0| 20 62 65 20 77 72 69 74 | 74 65 6e 20 61 73 20 61 | be writ|ten as a|
|000059e0| 20 6c 69 73 74 20 6f 66 | 20 63 6f 6d 6d 61 2d 73 | list of| comma-s|
|000059f0| 65 70 61 72 61 74 65 64 | 20 76 61 6c 75 65 73 20 |eparated| values |
|00005a00| 28 69 74 65 6d 73 29 20 | 62 65 74 77 65 65 6e 0d |(items) |between.|
|00005a10| 73 71 75 61 72 65 20 62 | 72 61 63 6b 65 74 73 2e |square b|rackets.|
|00005a20| 20 20 4c 69 73 74 20 69 | 74 65 6d 73 20 6e 65 65 | List i|tems nee|
|00005a30| 64 20 6e 6f 74 20 61 6c | 6c 20 68 61 76 65 20 74 |d not al|l have t|
|00005a40| 68 65 20 73 61 6d 65 20 | 74 79 70 65 2e 0d 0d 5c |he same |type...\|
|00005a50| 62 63 6f 64 65 5c 62 65 | 67 69 6e 7b 76 65 72 62 |bcode\be|gin{verb|
|00005a60| 61 74 69 6d 7d 0d 3e 3e | 3e 20 61 20 3d 20 5b 27 |atim}.>>|> a = ['|
|00005a70| 73 70 61 6d 27 2c 20 27 | 65 67 67 73 27 2c 20 31 |spam', '|eggs', 1|
|00005a80| 30 30 2c 20 31 32 33 34 | 5d 0d 3e 3e 3e 20 61 0d |00, 1234|].>>> a.|
|00005a90| 5b 27 73 70 61 6d 27 2c | 20 27 65 67 67 73 27 2c |['spam',| 'eggs',|
|00005aa0| 20 31 30 30 2c 20 31 32 | 33 34 5d 0d 3e 3e 3e 20 | 100, 12|34].>>> |
|00005ab0| 0d 5c 65 6e 64 7b 76 65 | 72 62 61 74 69 6d 7d 5c |.\end{ve|rbatim}\|
|00005ac0| 65 63 6f 64 65 0d 25 0d | 4c 69 6b 65 20 73 74 72 |ecode.%.|Like str|
|00005ad0| 69 6e 67 20 69 6e 64 69 | 63 65 73 2c 20 6c 69 73 |ing indi|ces, lis|
|00005ae0| 74 20 69 6e 64 69 63 65 | 73 20 73 74 61 72 74 20 |t indice|s start |
|00005af0| 61 74 20 30 2c 20 61 6e | 64 20 6c 69 73 74 73 20 |at 0, an|d lists |
|00005b00| 63 61 6e 20 62 65 20 73 | 6c 69 63 65 64 2c 0d 63 |can be s|liced,.c|
|00005b10| 6f 6e 63 61 74 65 6e 61 | 74 65 64 20 61 6e 64 20 |oncatena|ted and |
|00005b20| 73 6f 20 6f 6e 3a 0d 0d | 5c 62 63 6f 64 65 5c 62 |so on:..|\bcode\b|
|00005b30| 65 67 69 6e 7b 76 65 72 | 62 61 74 69 6d 7d 0d 3e |egin{ver|batim}.>|
|00005b40| 3e 3e 20 61 5b 30 5d 0d | 27 73 70 61 6d 27 0d 3e |>> a[0].|'spam'.>|
|00005b50| 3e 3e 20 61 5b 33 5d 0d | 31 32 33 34 0d 3e 3e 3e |>> a[3].|1234.>>>|
|00005b60| 20 61 5b 2d 32 5d 0d 31 | 30 30 0d 3e 3e 3e 20 61 | a[-2].1|00.>>> a|
|00005b70| 5b 31 3a 2d 31 5d 0d 5b | 27 65 67 67 73 27 2c 20 |[1:-1].[|'eggs', |
|00005b80| 31 30 30 5d 0d 3e 3e 3e | 20 61 5b 3a 32 5d 20 2b |100].>>>| a[:2] +|
|00005b90| 20 5b 27 62 61 63 6f 6e | 27 2c 20 32 2a 32 5d 0d | ['bacon|', 2*2].|
|00005ba0| 5b 27 73 70 61 6d 27 2c | 20 27 65 67 67 73 27 2c |['spam',| 'eggs',|
|00005bb0| 20 27 62 61 63 6f 6e 27 | 2c 20 34 5d 0d 3e 3e 3e | 'bacon'|, 4].>>>|
|00005bc0| 20 33 2a 61 5b 3a 33 5d | 20 2b 20 5b 27 42 6f 65 | 3*a[:3]| + ['Boe|
|00005bd0| 21 27 5d 0d 5b 27 73 70 | 61 6d 27 2c 20 27 65 67 |!'].['sp|am', 'eg|
|00005be0| 67 73 27 2c 20 31 30 30 | 2c 20 27 73 70 61 6d 27 |gs', 100|, 'spam'|
|00005bf0| 2c 20 27 65 67 67 73 27 | 2c 20 31 30 30 2c 20 27 |, 'eggs'|, 100, '|
|00005c00| 73 70 61 6d 27 2c 20 27 | 65 67 67 73 27 2c 20 31 |spam', '|eggs', 1|
|00005c10| 30 30 2c 20 27 42 6f 65 | 21 27 5d 0d 3e 3e 3e 20 |00, 'Boe|!'].>>> |
|00005c20| 0d 5c 65 6e 64 7b 76 65 | 72 62 61 74 69 6d 7d 5c |.\end{ve|rbatim}\|
|00005c30| 65 63 6f 64 65 0d 25 0d | 55 6e 6c 69 6b 65 20 73 |ecode.%.|Unlike s|
|00005c40| 74 72 69 6e 67 73 2c 20 | 77 68 69 63 68 20 61 72 |trings, |which ar|
|00005c50| 65 20 7b 5c 65 6d 20 69 | 6d 6d 75 74 61 62 6c 65 |e {\em i|mmutable|
|00005c60| 7d 2c 20 69 74 20 69 73 | 20 70 6f 73 73 69 62 6c |}, it is| possibl|
|00005c70| 65 20 74 6f 20 63 68 61 | 6e 67 65 0d 69 6e 64 69 |e to cha|nge.indi|
|00005c80| 76 69 64 75 61 6c 20 65 | 6c 65 6d 65 6e 74 73 20 |vidual e|lements |
|00005c90| 6f 66 20 61 20 6c 69 73 | 74 3a 0d 0d 5c 62 63 6f |of a lis|t:..\bco|
|00005ca0| 64 65 5c 62 65 67 69 6e | 7b 76 65 72 62 61 74 69 |de\begin|{verbati|
|00005cb0| 6d 7d 0d 3e 3e 3e 20 61 | 0d 5b 27 73 70 61 6d 27 |m}.>>> a|.['spam'|
|00005cc0| 2c 20 27 65 67 67 73 27 | 2c 20 31 30 30 2c 20 31 |, 'eggs'|, 100, 1|
|00005cd0| 32 33 34 5d 0d 3e 3e 3e | 20 61 5b 32 5d 20 3d 20 |234].>>>| a[2] = |
|00005ce0| 61 5b 32 5d 20 2b 20 32 | 33 0d 3e 3e 3e 20 61 0d |a[2] + 2|3.>>> a.|
|00005cf0| 5b 27 73 70 61 6d 27 2c | 20 27 65 67 67 73 27 2c |['spam',| 'eggs',|
|00005d00| 20 31 32 33 2c 20 31 32 | 33 34 5d 0d 3e 3e 3e 0d | 123, 12|34].>>>.|
|00005d10| 5c 65 6e 64 7b 76 65 72 | 62 61 74 69 6d 7d 5c 65 |\end{ver|batim}\e|
|00005d20| 63 6f 64 65 0d 25 0d 41 | 73 73 69 67 6e 6d 65 6e |code.%.A|ssignmen|
|00005d30| 74 20 74 6f 20 73 6c 69 | 63 65 73 20 69 73 20 61 |t to sli|ces is a|
|00005d40| 6c 73 6f 20 70 6f 73 73 | 69 62 6c 65 2c 20 61 6e |lso poss|ible, an|
|00005d50| 64 20 74 68 69 73 20 63 | 61 6e 20 65 76 65 6e 20 |d this c|an even |
|00005d60| 63 68 61 6e 67 65 20 74 | 68 65 20 73 69 7a 65 0d |change t|he size.|
|00005d70| 6f 66 20 74 68 65 20 6c | 69 73 74 3a 0d 0d 5c 62 |of the l|ist:..\b|
|00005d80| 63 6f 64 65 5c 62 65 67 | 69 6e 7b 76 65 72 62 61 |code\beg|in{verba|
|00005d90| 74 69 6d 7d 0d 3e 3e 3e | 20 23 20 52 65 70 6c 61 |tim}.>>>| # Repla|
|00005da0| 63 65 20 73 6f 6d 65 20 | 69 74 65 6d 73 3a 0d 2e |ce some |items:..|
|00005db0| 2e 2e 20 61 5b 30 3a 32 | 5d 20 3d 20 5b 31 2c 20 |.. a[0:2|] = [1, |
|00005dc0| 31 32 5d 0d 3e 3e 3e 20 | 61 0d 5b 31 2c 20 31 32 |12].>>> |a.[1, 12|
|00005dd0| 2c 20 31 32 33 2c 20 31 | 32 33 34 5d 0d 3e 3e 3e |, 123, 1|234].>>>|
|00005de0| 20 23 20 52 65 6d 6f 76 | 65 20 73 6f 6d 65 3a 0d | # Remov|e some:.|
|00005df0| 2e 2e 2e 20 61 5b 30 3a | 32 5d 20 3d 20 5b 5d 0d |... a[0:|2] = [].|
|00005e00| 3e 3e 3e 20 61 0d 5b 31 | 32 33 2c 20 31 32 33 34 |>>> a.[1|23, 1234|
|00005e10| 5d 0d 3e 3e 3e 20 23 20 | 49 6e 73 65 72 74 20 73 |].>>> # |Insert s|
|00005e20| 6f 6d 65 3a 0d 2e 2e 2e | 20 61 5b 31 3a 31 5d 20 |ome:....| a[1:1] |
|00005e30| 3d 20 5b 27 62 6c 65 74 | 63 68 27 2c 20 27 78 79 |= ['blet|ch', 'xy|
|00005e40| 7a 7a 79 27 5d 0d 3e 3e | 3e 20 61 0d 5b 31 32 33 |zzy'].>>|> a.[123|
|00005e50| 2c 20 27 62 6c 65 74 63 | 68 27 2c 20 27 78 79 7a |, 'bletc|h', 'xyz|
|00005e60| 7a 79 27 2c 20 31 32 33 | 34 5d 0d 3e 3e 3e 20 61 |zy', 123|4].>>> a|
|00005e70| 5b 3a 30 5d 20 3d 20 61 | 20 20 20 20 20 23 20 49 |[:0] = a| # I|
|00005e80| 6e 73 65 72 74 20 28 61 | 20 63 6f 70 79 20 6f 66 |nsert (a| copy of|
|00005e90| 29 20 69 74 73 65 6c 66 | 20 61 74 20 74 68 65 20 |) itself| at the |
|00005ea0| 62 65 67 69 6e 6e 69 6e | 67 0d 3e 3e 3e 20 61 0d |beginnin|g.>>> a.|
|00005eb0| 5b 31 32 33 2c 20 27 62 | 6c 65 74 63 68 27 2c 20 |[123, 'b|letch', |
|00005ec0| 27 78 79 7a 7a 79 27 2c | 20 31 32 33 34 2c 20 31 |'xyzzy',| 1234, 1|
|00005ed0| 32 33 2c 20 27 62 6c 65 | 74 63 68 27 2c 20 27 78 |23, 'ble|tch', 'x|
|00005ee0| 79 7a 7a 79 27 2c 20 31 | 32 33 34 5d 0d 3e 3e 3e |yzzy', 1|234].>>>|
|00005ef0| 20 0d 5c 65 6e 64 7b 76 | 65 72 62 61 74 69 6d 7d | .\end{v|erbatim}|
|00005f00| 5c 65 63 6f 64 65 0d 25 | 0d 54 68 65 20 62 75 69 |\ecode.%|.The bui|
|00005f10| 6c 74 2d 69 6e 20 66 75 | 6e 63 74 69 6f 6e 20 7b |lt-in fu|nction {|
|00005f20| 5c 74 74 20 6c 65 6e 28 | 29 7d 20 61 6c 73 6f 20 |\tt len(|)} also |
|00005f30| 61 70 70 6c 69 65 73 20 | 74 6f 20 6c 69 73 74 73 |applies |to lists|
|00005f40| 3a 0d 0d 5c 62 63 6f 64 | 65 5c 62 65 67 69 6e 7b |:..\bcod|e\begin{|
|00005f50| 76 65 72 62 61 74 69 6d | 7d 0d 3e 3e 3e 20 6c 65 |verbatim|}.>>> le|
|00005f60| 6e 28 61 29 0d 38 0d 3e | 3e 3e 20 0d 5c 65 6e 64 |n(a).8.>|>> .\end|
|00005f70| 7b 76 65 72 62 61 74 69 | 6d 7d 5c 65 63 6f 64 65 |{verbati|m}\ecode|
|00005f80| 0d 25 0d 49 74 20 69 73 | 20 70 6f 73 73 69 62 6c |.%.It is| possibl|
|00005f90| 65 20 74 6f 20 6e 65 73 | 74 20 6c 69 73 74 73 20 |e to nes|t lists |
|00005fa0| 28 63 72 65 61 74 65 20 | 6c 69 73 74 73 20 63 6f |(create |lists co|
|00005fb0| 6e 74 61 69 6e 69 6e 67 | 20 6f 74 68 65 72 20 6c |ntaining| other l|
|00005fc0| 69 73 74 73 29 2c 0d 66 | 6f 72 20 65 78 61 6d 70 |ists),.f|or examp|
|00005fd0| 6c 65 3a 0d 0d 5c 62 63 | 6f 64 65 5c 62 65 67 69 |le:..\bc|ode\begi|
|00005fe0| 6e 7b 76 65 72 62 61 74 | 69 6d 7d 0d 3e 3e 3e 20 |n{verbat|im}.>>> |
|00005ff0| 71 20 3d 20 5b 32 2c 20 | 33 5d 0d 3e 3e 3e 20 70 |q = [2, |3].>>> p|
|00006000| 20 3d 20 5b 31 2c 20 71 | 2c 20 34 5d 0d 3e 3e 3e | = [1, q|, 4].>>>|
|00006010| 20 6c 65 6e 28 70 29 0d | 33 0d 3e 3e 3e 20 70 5b | len(p).|3.>>> p[|
|00006020| 31 5d 0d 5b 32 2c 20 33 | 5d 0d 3e 3e 3e 20 70 5b |1].[2, 3|].>>> p[|
|00006030| 31 5d 5b 30 5d 0d 32 0d | 3e 3e 3e 20 70 5b 31 5d |1][0].2.|>>> p[1]|
|00006040| 2e 61 70 70 65 6e 64 28 | 27 78 74 72 61 27 29 20 |.append(|'xtra') |
|00006050| 20 20 20 20 23 20 53 65 | 65 20 73 65 63 74 69 6f | # Se|e sectio|
|00006060| 6e 20 35 2e 31 0d 3e 3e | 3e 20 70 0d 5b 31 2c 20 |n 5.1.>>|> p.[1, |
|00006070| 5b 32 2c 20 33 2c 20 27 | 78 74 72 61 27 5d 2c 20 |[2, 3, '|xtra'], |
|00006080| 34 5d 0d 3e 3e 3e 20 71 | 0d 5b 32 2c 20 33 2c 20 |4].>>> q|.[2, 3, |
|00006090| 27 78 74 72 61 27 5d 0d | 3e 3e 3e 0d 5c 65 6e 64 |'xtra'].|>>>.\end|
|000060a0| 7b 76 65 72 62 61 74 69 | 6d 7d 5c 65 63 6f 64 65 |{verbati|m}\ecode|
|000060b0| 0d 25 0d 4e 6f 74 65 20 | 74 68 61 74 20 69 6e 20 |.%.Note |that in |
|000060c0| 74 68 65 20 6c 61 73 74 | 20 65 78 61 6d 70 6c 65 |the last| example|
|000060d0| 2c 20 7b 5c 74 74 20 70 | 5b 31 5d 7d 20 61 6e 64 |, {\tt p|[1]} and|
|000060e0| 20 7b 5c 74 74 20 71 7d | 20 72 65 61 6c 6c 79 20 | {\tt q}| really |
|000060f0| 72 65 66 65 72 20 74 6f | 0d 74 68 65 20 73 61 6d |refer to|.the sam|
|00006100| 65 20 6f 62 6a 65 63 74 | 21 20 20 57 65 27 6c 6c |e object|! We'll|
|00006110| 20 63 6f 6d 65 20 62 61 | 63 6b 20 74 6f 20 7b 5c | come ba|ck to {\|
|00006120| 65 6d 20 6f 62 6a 65 63 | 74 20 73 65 6d 61 6e 74 |em objec|t semant|
|00006130| 69 63 73 7d 20 6c 61 74 | 65 72 2e 0d 0d 5c 73 65 |ics} lat|er...\se|
|00006140| 63 74 69 6f 6e 7b 46 69 | 72 73 74 20 53 74 65 70 |ction{Fi|rst Step|
|00006150| 73 20 54 6f 77 61 72 64 | 73 20 50 72 6f 67 72 61 |s Toward|s Progra|
|00006160| 6d 6d 69 6e 67 7d 0d 0d | 4f 66 20 63 6f 75 72 73 |mming}..|Of cours|
|00006170| 65 2c 20 77 65 20 63 61 | 6e 20 75 73 65 20 50 79 |e, we ca|n use Py|
|00006180| 74 68 6f 6e 20 66 6f 72 | 20 6d 6f 72 65 20 63 6f |thon for| more co|
|00006190| 6d 70 6c 69 63 61 74 65 | 64 20 74 61 73 6b 73 20 |mplicate|d tasks |
|000061a0| 74 68 61 6e 20 61 64 64 | 69 6e 67 0d 74 77 6f 20 |than add|ing.two |
|000061b0| 61 6e 64 20 74 77 6f 20 | 74 6f 67 65 74 68 65 72 |and two |together|
|000061c0| 2e 20 20 46 6f 72 20 69 | 6e 73 74 61 6e 63 65 2c |. For i|nstance,|
|000061d0| 20 77 65 20 63 61 6e 20 | 77 72 69 74 65 20 61 6e | we can |write an|
|000061e0| 20 69 6e 69 74 69 61 6c | 0d 73 75 62 73 65 71 75 | initial|.subsequ|
|000061f0| 65 6e 63 65 20 6f 66 20 | 74 68 65 20 7b 5c 65 6d |ence of |the {\em|
|00006200| 20 46 69 62 6f 6e 61 63 | 63 69 7d 20 73 65 72 69 | Fibonac|ci} seri|
|00006210| 65 73 20 61 73 20 66 6f | 6c 6c 6f 77 73 3a 0d 0d |es as fo|llows:..|
|00006220| 5c 62 63 6f 64 65 5c 62 | 65 67 69 6e 7b 76 65 72 |\bcode\b|egin{ver|
|00006230| 62 61 74 69 6d 7d 0d 3e | 3e 3e 20 23 20 46 69 62 |batim}.>|>> # Fib|
|00006240| 6f 6e 61 63 63 69 20 73 | 65 72 69 65 73 3a 0d 2e |onacci s|eries:..|
|00006250| 2e 2e 20 23 20 74 68 65 | 20 73 75 6d 20 6f 66 20 |.. # the| sum of |
|00006260| 74 77 6f 20 65 6c 65 6d | 65 6e 74 73 20 64 65 66 |two elem|ents def|
|00006270| 69 6e 65 73 20 74 68 65 | 20 6e 65 78 74 0d 2e 2e |ines the| next...|
|00006280| 2e 20 61 2c 20 62 20 3d | 20 30 2c 20 31 0d 3e 3e |. a, b =| 0, 1.>>|
|00006290| 3e 20 77 68 69 6c 65 20 | 62 20 3c 20 31 30 3a 0d |> while |b < 10:.|
|000062a0| 2e 2e 2e 20 20 20 20 20 | 20 20 70 72 69 6e 74 20 |... | print |
|000062b0| 62 0d 2e 2e 2e 20 20 20 | 20 20 20 20 61 2c 20 62 |b.... | a, b|
|000062c0| 20 3d 20 62 2c 20 61 2b | 62 0d 2e 2e 2e 20 0d 31 | = b, a+|b.... .1|
|000062d0| 0d 31 0d 32 0d 33 0d 35 | 0d 38 0d 3e 3e 3e 20 0d |.1.2.3.5|.8.>>> .|
|000062e0| 5c 65 6e 64 7b 76 65 72 | 62 61 74 69 6d 7d 5c 65 |\end{ver|batim}\e|
|000062f0| 63 6f 64 65 0d 25 0d 54 | 68 69 73 20 65 78 61 6d |code.%.T|his exam|
|00006300| 70 6c 65 20 69 6e 74 72 | 6f 64 75 63 65 73 20 73 |ple intr|oduces s|
|00006310| 65 76 65 72 61 6c 20 6e | 65 77 20 66 65 61 74 75 |everal n|ew featu|
|00006320| 72 65 73 2e 0d 0d 5c 62 | 65 67 69 6e 7b 69 74 65 |res...\b|egin{ite|
|00006330| 6d 69 7a 65 7d 0d 0d 5c | 69 74 65 6d 0d 54 68 65 |mize}..\|item.The|
|00006340| 20 66 69 72 73 74 20 6c | 69 6e 65 20 63 6f 6e 74 | first l|ine cont|
|00006350| 61 69 6e 73 20 61 20 7b | 5c 65 6d 20 6d 75 6c 74 |ains a {|\em mult|
|00006360| 69 70 6c 65 20 61 73 73 | 69 67 6e 6d 65 6e 74 7d |iple ass|ignment}|
|00006370| 3a 20 74 68 65 20 76 61 | 72 69 61 62 6c 65 73 0d |: the va|riables.|
|00006380| 7b 5c 74 74 20 61 7d 20 | 61 6e 64 20 7b 5c 74 74 |{\tt a} |and {\tt|
|00006390| 20 62 7d 20 73 69 6d 75 | 6c 74 61 6e 65 6f 75 73 | b} simu|ltaneous|
|000063a0| 6c 79 20 67 65 74 20 74 | 68 65 20 6e 65 77 20 76 |ly get t|he new v|
|000063b0| 61 6c 75 65 73 20 30 20 | 61 6e 64 20 31 2e 20 20 |alues 0 |and 1. |
|000063c0| 4f 6e 20 74 68 65 0d 6c | 61 73 74 20 6c 69 6e 65 |On the.l|ast line|
|000063d0| 20 74 68 69 73 20 69 73 | 20 75 73 65 64 20 61 67 | this is| used ag|
|000063e0| 61 69 6e 2c 20 64 65 6d | 6f 6e 73 74 72 61 74 69 |ain, dem|onstrati|
|000063f0| 6e 67 20 74 68 61 74 20 | 74 68 65 20 65 78 70 72 |ng that |the expr|
+--------+-------------------------+-------------------------+--------+--------+
Only 25.0 KB of data is shown above.